PostgreSQL Cheat Sheet
Some things to note about SQL:
PSQL Commands
\list - list all available databases
\dt - list all tables in the current database
\d+ tablename - look at a table's structure
\connect testdb - connect to database (specify name)
\c testdb - connect to database (shorthand)
\conninfo - check connection info
\? - all psql commands
\help - all PostgreSQL commands
\q - quitSQL Commands
Create a database
Create a table
INSERT data into a table
SELECT data from a table
Select all columns (with wildcard)
SELECT specific columns
Select distinct values from a column
Selecting using WHERE
SELECT using a WHERE clause
NOT EQUAL
LIKE (usually uses a wildcard, '%')
ILIKE (case insensitive)
ORDER BY
AND/OR
IN/NOT IN
LIMIT (returns the first rows)
LIMIT + OFFSET
Select an aggregate
COUNT
MAX/MIN values
UPDATE data in a table
ALTER table columns and constraints
DELETE data from a table
DROP a table
JOINing Tables

GROUP BY
Last updated