PostgreSQL

Select Statement

The SELECT statement is used to retrieve the rows from one or more tables in a database.

Selecting All Columns

To select all the rows of a table, use the asterisk (*).

Syntax

SELECT <query-parameters> FROM <table-name>;

Example #1

SELECT * FROM Companies;
Result from example #1
Name Type Founded HQ
Walmart Retail 1962 United States
Disney Entertainment 1923 United States
PayPal Finance 1998 United States
Blackberry Technology 1984 Canada

Tip: If you have a lot of rows use ctrl-c or cmd-c to escape from viewing more rows.

Selecting Specific Columns

Specific columns can be retrieved from a table too.

Syntax

SELECT <column-name> FROM <table-name>;

Example #2

SELECT name, founded, hq FROM Companies;
Result from example #2
Name Founded HQ
Walmart 1962 United States
Disney 1923 United States
PayPal 1998 United States
Blackberry 1984 Canada