Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 895 Bytes

querying.md

File metadata and controls

39 lines (30 loc) · 895 Bytes

Querying our tables

Retrieve all data in a table :

SELECT * FROM "user";

* is a wildcard, it indicates that you want all table columns. You can retrieve specific columns by naming it :

SELECT name, email FROM "user";

Be careful, the upper commands will retrieve all table rows, that could cause performance problems if your table holds many rows. You can limit the number of returned rows :

SELECT * FROM "user" LIMIT 2;

You can easily order your query results, for example by name :

SELECT * FROM "user" ORDER BY name LIMIT 10;

Specify query conditions with the WHERE clause :

SELECT *
FROM "user"
WHERE name = 'Titi'; -- Gets only Titi

SELECT *
FROM "user"
WHERE birthdate < '2000-01-01'; -- selects dates before 2000

postgres doc - querying a table