simshadows

SQL and Common Relational DBMS Features Cheatsheet

I am using Microsoft SQL Server these days, so this cheatsheet will currently assume you’re using it.

I will rework this cheatsheet to be more DBMS-agnostic later.

Resources

References:

SELECT Statements

Whole Table

SELECT * FROM mytable;

Common Clauses

SELECT
    MyCol1,
    MyCol2,
    MyCol3,
    SUM(MyCol4) AS MySum
FROM MyTable
GROUP BY
    MyCol2,
    MyCol3
WHERE 
    MyCol1 = '1969-04-01'
    AND MyCol2 in ('mystr1', 'mystr2')
    AND (
        MyCol3 <= 4
        OR MyCol3 BETWEEN 10 AND 20
    )
HAVING
    SUM(MyCol4) > 2
ORDER BY
    MyCol1 ASC,
    MyCol3 DESC
;

Joins

(TODO)

Unions

(TODO)