Skip to the content ForoHackers
Log inJoin

SQL: start here

SQL
#2903 · · Quote · Report

SQL is the standard language for asking questions of relational data and for changing it. You describe the result you want, not the steps to compute it, and the database decides how. It is one of the most durable skills in computing, used by analysts, backend developers and administrators alike.

Key concepts

  • Declarative queries: you state what rows you want; the planner picks scans, indexes and join methods.
  • Joins: combine tables on matching keys; inner, left, right and full joins differ in which unmatched rows survive.
  • Aggregation: group rows and compute counts, sums and averages, then filter the groups.
  • Set thinking: a table is a set of rows, so work on whole sets rather than looping row by row.
  • Constraints: primary and foreign keys, uniqueness and checks keep bad data out.

Vocabulary

  • NULL: a marker for an unknown value; comparisons with it are neither true nor false.
  • Window function: a calculation across related rows that keeps each row, such as a running total.
  • CTE: common table expression, a named subquery that makes a long query readable.
  • DDL and DML: statements that define structure, and statements that read or change data.

What to study, in order

  1. Select, filter, sort and limit rows from a single table.
  2. Join two and then three tables, and predict the row count before running it.
  3. Group, aggregate and filter groups; learn why NULL needs special handling.
  4. Subqueries, CTEs and window functions on a real dataset.
  5. Design tables with keys and constraints, and insert, update and delete safely inside a transaction.
  6. Read a query plan, add an index and measure a slow query before and after.

Related tags

#databases #data-science #data-engineering #nosql

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply