Workspace

SQL

data querying product analytics and databases

Definition first

What SQL means

SQL is a programming language for writing exact instructions, often used for data querying product analytics and databases. Start with one mental model: input goes through steps and becomes output.

Minimum run factsFile query.sqlRun psql -f query.sqlHabit Start with SELECT columns then add WHERE then JOIN then aggregate
Program

An ordered set of instructions. It reads input, follows rules, and produces output.

Value and variable

A value is data. A variable is the name you use to hold and reuse that data.

Function

A named piece of work. It takes input, does one job, and can return a result.

Runtime

PostgreSQL compatible SQL is the place that actually runs code from query.sql.

First readable code

Select

columns table rows
SELECT name, score FROM users;
Output name score rows

Language lineage

SQL family tree

See where SQL comes from, which languages feel close, and what to learn next.

roots
relational algebraSEQUEL
currentSQLRelational data family
familyRelational data family
best used for

querying, joining, grouping, and protecting production data

Zero base path

1Read one rule2Predict output3Type from memory4Run checklist5Repeat with one change

Question bank

Search before practice

Pick a stage or search across the open programming bank. Jump straight to the matching drill.

18 matching questions
Q 1ChoiceStage 1 definitions

SQL practice 1

SQL question 1. Choose the statement that matches select columns.

Q 2ChoiceStage 1 definitions

SQL practice 2

SQL question 2. Choose the statement that matches where filter.

Q 3ChoiceStage 1 definitions

SQL practice 3

SQL question 3. Choose the statement that matches count aggregate.

Q 4ChoiceStage 1 definitions

SQL practice 4

SQL question 4. Choose the statement that matches join tables.

Q 5ChoiceStage 1 definitions

SQL practice 5

SQL question 5. Choose the statement that matches select columns.

Q 6ChoiceStage 1 definitions

SQL practice 6

SQL question 6. Choose the statement that matches where filter.

Q 7ChoiceStage 1 definitions

SQL practice 7

SQL question 7. Choose the statement that matches count aggregate.

Q 8ChoiceStage 1 definitions

SQL practice 8

SQL question 8. Choose the statement that matches join tables.

Q 9ChoiceStage 1 definitions

SQL practice 9

SQL question 9. Choose the statement that matches select columns.

Q 10ChoiceStage 1 definitions

SQL practice 10

SQL question 10. Choose the statement that matches where filter.

Q 11ChoiceStage 1 definitions

SQL practice 11

SQL question 11. Choose the statement that matches count aggregate.

Q 12ChoiceStage 1 definitions

SQL practice 12

SQL question 12. Choose the statement that matches join tables.

Q 13ChoiceStage 1 definitions

SQL practice 13

SQL question 13. Choose the statement that matches select columns.

Q 14ChoiceStage 1 definitions

SQL practice 14

SQL question 14. Choose the statement that matches where filter.

Q 15ChoiceStage 1 definitions

SQL practice 15

SQL question 15. Choose the statement that matches count aggregate.

Q 16ChoiceStage 1 definitions

SQL practice 16

SQL question 16. Choose the statement that matches join tables.

Q 17ChoiceStage 1 definitions

SQL practice 17

SQL question 17. Choose the statement that matches select columns.

Q 18ChoiceStage 1 definitions

SQL practice 18

SQL question 18. Choose the statement that matches where filter.

Multiple choice

SQL practice 1

Q 1Choicenew

SQL question 1. Choose the statement that matches select columns.

SELECT name FROM users;

Reference

Patterns for query.sql

PostgreSQL compatible SQLpsql -f query.sql
Recall from memoryRead a small point then write it back without looking
Trace the codeWrite variable values line by line before you run the answer
Type it yourselfCopy less type more and fix one small error at a time

columns table rows

Select

SELECT name, score FROM users;
  • Select only needed columns
  • Read from one table first
  • Add limits while exploring

where order limit

Filter

SELECT name FROM users WHERE score >= 60;
  • WHERE filters rows
  • ORDER BY sorts
  • LIMIT protects exploration

count sum avg group by

Group

SELECT role, COUNT(*) FROM users GROUP BY role;
  • Aggregate after filtering
  • Group by non aggregate columns
  • Name metrics clearly