PostgreSQL Select

PostgreSQL Select

The PostgreSQL SELECT statement is used to query records from a table.

Select syntax

-- select all records from table
SELECT * FROM table_name

-- select specific columns 
SELECT column_1, column_2 FROM table_name

-- select the records that meet the conditions
SELECT * FROM table_name WHERE {conditions}

Select example

Goods table

idgood_typenamedescriptionpriceinsert_date
1ACar_1Car 1 description1002018-07-21 08:45:57.311809
2ACar_2Car 2 description2002018-07-21 08:45:57.311809
3ACar_3Car 3 description1002018-07-21 08:45:57.311809
4BBoat_4Boat 4 description5002018-07-21 08:45:57.311809
5BBoat_5Boat 5 description3002018-07-21 08:45:57.311809
6CTrain_1Train 123 description8002018-07-21 08:45:57.311809
SELECT * FROM goods;

SELECT id, name FROM goods;

SELECT id, name FROM goods WHERE id > 3;

SELECT * FROM goods WHERE name LIKE '%Boat%';