SQL

Revision as of 01:42, 12 February 2024 by David (talk | contribs) (Created page with "SQL basics ==Common functions== See [https://www.postgresql.org/docs/16/functions-math.html Postgres math functions] and [https://www.postgresql.org/docs/current/functions-conditional.html Postgres conditional functions]. * Average * Sum * Round * [https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL Coalesce] - return the first non-null parameter. * [https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIO...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

SQL basics


Common functions

See Postgres math functions and Postgres conditional functions.

  • Average
  • Sum
  • Round
  • Coalesce - return the first non-null parameter.
  • Case

Joins

Joins merge two tables into a single table. You can think of this like an outer product, applying some conditions to subset from every possible combination of rows from the two tables.

  • Inner join - creates rows only if keys match between the rows
  • Left join - keep all rows from the left table
  • Right join - keep all rows from the right table
  • Outer join - keep rows from both tables.

Subqueries