Random posts about ... stuff
by Q
SELECT
retrieves rows from zero or more tables.
WITH
All queries will be computed and serve as temporary tables that can be referenced in the FROM
list. A WITH
query can be referenced more than once while computed only once.
FROM
If more than one element is specified, they are cross-joined together.
WHERE
All rows do not satisfy the condition are eliminated from the output.
GROUP BY
/aggregate function calls/Having
The output will be combined into groups of rows then aggregated. If the Having
clause is present, it eliminates groups that do not satisfy the given condition.
SELECT
SELECT DISTINCT
/SELECT DISTINCT ON
/SELECT ALL
SELECT DISTINCT
eliminates duplicate rows from the result.SELECT DISTINCT ON
eliminates duplicate rows that match on all the specified expressionsSELECT ALL
returns all candidate rows, including duplicates. It is the default behaviorUNION
/INTERSECT
/EXCEPT
UNION
returns all rows that are in one or both of the result setsINTERSECT
returns all rows that are strictly in both result setsEXCEPT
returns the rows that are in the fist result but not in the secondIn all three cases, duplicate rows are eliminated unless ALL
is specified
ORDER BY
The returned rows are sorted in the specified order
LIMIT
The SELECT
statement only returns a subset of the result rows
FOR UPDATE
/FOR NO KEY UPDATE
/FOR SHARE
/FOR KEY SHARE
The SELECT
statement locks the selected rows against concurrent updatesTo join the table flights
with the table logs
:
To retrieve from the table flights
with some constraints:
To obtain the union of the tables flights
with logs
:
References:
Updated: 12 June 2020