Tag archive
Commands grouped around the same concept, pattern, or recurring problem.
Use `EXISTS` when you only need to test whether a related row exists, not return one output row per match.
Return all rows from both tables, filling NULLs on either side when there is no matching row.
Remove rows from one table based on matching rows in another table.
Find rows whose date or timestamp intervals intersect by checking that neither range ends before the other begins — using the `OVERLAPS` operator in PostgreSQL or a manual comparison in other engines.
Return all rows from the right table and matching rows from the left, filling NULL where no match exists.
Return all rows from the left table and matching rows from the right, filling NULL where no match exists.
Put right-table filters in the `ON` clause when you want to keep unmatched left-side rows.
Return rows from one table that have no corresponding row in a second table using a LEFT JOIN with a NULL check.
Produce every possible pairing of rows from two tables using `CROSS JOIN`.
Reference the same table twice using aliases to compare or relate rows within the same dataset.
Join two tables using a comparison other than equality — such as `BETWEEN` or `<` — to match rows based on ranges rather than exact values.
Combine rows from two tables when matching keys exist in both tables.
Use `LATERAL` (or `CROSS APPLY` on SQL Server) to let a subquery reference columns from the preceding table in the `FROM` clause.
Use a join inside an `UPDATE` statement to copy or derive values from a related table.
Supply a small set of constant rows directly inside a query using a `VALUES` derived table — no temporary table or CTE required.