Lesson 1 of 3Module 1 · 0% of course
‹ PrevNext ›
Explore › CS, Python & AI Engineering › SQL & APIs › Talking to data
SQL & APIs · Talking to data

SQL: SELECT, WHERE, JOIN

The language of every trade database. Reconcile two tables in one query.

15 min · 4 steps · videoJump to quiz ↓
CS50 SQL - Lecture 0 - Querying CS50 · 79 min
Open in YouTube
Step 1 of 4 · Overview15 min read ·
SELECT o.id, o.qty AS our_qty, t.qty AS their_qty
FROM ours o
FULL OUTER JOIN theirs t ON o.id = t.id
WHERE o.id IS NULL           -- missing in ours
   OR t.id IS NULL           -- missing at counterparty
   OR o.qty <> t.qty;        -- qty break
The whole Lesson 1 reconciler as one query.
JOINKeeps
INNERonly ids in both tables
LEFTall of ours, matches from theirs (NULL if none)
FULL OUTEReverything from both sides
FROM/JOIN
pick tables
→
WHERE
filter rows
→
GROUP BY
bucket
→
HAVING
filter buckets
→
SELECT
choose columns
→
ORDER BY
sort
Logical order SQL actually runs in, not the order you write it.
Next: Practice
‹ PrevNext ›