SQL: Selecting, Filtering and Ordering Rows
Asking a database for the rows and columns you want with SELECT, WHERE and ORDER BY. The query says what is wanted, and the database decides how to fetch it.
What a learner can do afterwards
- Write a query that returns named columns for the rows matching a condition
- Combine conditions with AND, OR and NOT and predict which rows survive
- Sort results and limit them, and say what changes when the order is reversed
1 · Read
SQL is the language for asking questions of relational databases. SELECT names the columns you want, FROM names the table, and WHERE keeps only the rows that pass your test. The query says what you want, and the database decides how to fetch it.
A library keeps a Books table with title, author, and borrowed_on columns. SELECT title, author FROM Books WHERE borrowed_on > '2025-06-01' returns just those columns for books borrowed after that date. ORDER BY title sorts the survivors by title, and LIMIT 10 trims the answer to the first ten.
Conditions combine with AND, OR, and NOT. AND keeps rows passing both sides, OR keeps rows passing either side, and NOT flips a test to keep the opposite rows. To predict an answer, apply the WHERE tests row by row and keep only rows where the whole condition holds.
Read every query as a pipeline: pick columns, keep rows, sort, then cut. Reversing the sort swaps the first and last rows, which is a handy check that ordering controls the output. Remember the tables must exist before any SELECT runs, because queries name tables and columns from the schema.
Name your columns, filter your rows, then sort and trim the answer.
2 · Watch
Take it off screen
Where it sits
8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.