“'Mr Bassington-Bassington has just telephoned, sir.'”

SQL

A programming language used to interact with relational databases. Its verbose, pseudo-English syntax (SELECT * FROM my_table WHERE my_column IS NOT NULL) is a relic from the COBOL era of computer programming. Every database system has its own dialect.

Cheatsheet

Find rows with duplicate values of column

SELECT t.* FROM my_table t
JOIN (
  SELECT my_col FROM my_table GROUP BY my_col HAVING COUNT(*) > 1
) dup ON t.my_col = dup.my_col
ORDER BY my_col

Pair adjacent rows using a window function

SELECT
  date AS end_date,
  LAG(date) OVER (ORDER BY date) AS start_date
FROM
  my_table

Posts