3.2 Basic SELECT Tutorial
Sort NULL first
SELECT *
FROM table_name
ORDER BY column1 ASC NULLS FIRST
Sort NULL last
SELECT *
FROM table_name
ORDER BY column1 ASC NULLS LAST
GROUP BY
Group by a specific column
SELECT *
FROM table_name
GROUP BY column1
Group by a specific column
SELECT count(*)
FROM table_name
GROUP BY column1
HAVING
Filter grouped data.
SELECT count(column1), column2
FROM table_name
GROUP BY column2
HAVING count(column1) > value1
JOIN
Combine two tables on a specific column
SELECT *
FROM table1
JOIN table2
ON table1.column1 = table2.column1
UNION
Combine two tables
SELECT column1, column2 FROM table1
UNION
SELECT column1, column2 FROM table2;
LIMIT, OFFSET
LIMIT numberthe maximum number of rows to returnOFFSET numberthe number of rows to skip
Get 10 rows after the 5th row
SELECT *
FROM table_name
OFFSET 5
LIMIT 10