Master Check: SELECT in Action
Put SELECT to work on real tasks
QUERY shuts down the extra panels. One terminal and three tasks remain in the hall: the exam for your first clearance.
The Academy doesn't trust words—only queries.
Over this module, you've built the basic toolkit of an archive reader. You can now do more than write:
SELECT *
FROM products;
You can ask the database a precise question.
You choose the columns you need:
SELECT name, price
FROM products;
Give them clear names:
SELECT
name AS product_name,
price AS product_price
FROM products;
Keep only the rows you need:
SELECT name, price
FROM products
WHERE price >= 10;
Handle missing values:
SELECT id, name, city
FROM users
WHERE city IS NULL;
Write compact filters using ranges, lists, and patterns:
SELECT name, category, price
FROM products
WHERE category IN ('Books', 'Toys')
AND price BETWEEN 10 AND 30
AND name LIKE 'C%';
Set the sort order:
SELECT name, price
FROM products
ORDER BY price DESC;
Take the first rows from that sorted result:
SELECT name, price
FROM products
ORDER BY price DESC
LIMIT 5;
Remove duplicates when you need a list of unique values:
SELECT DISTINCT status
FROM orders;
And add simple logic directly to the output:
SELECT
name,
price,
CASE
WHEN price < 15 THEN 'cheap'
WHEN price < 40 THEN 'mid-range'
ELSE 'expensive'
END AS segment
FROM products;
Now you need to see all of these pieces as parts of one tool.
Not separate commands.
Not a collection of unrelated operators.
A complete path from a table to a clear result.
QUERY: You don't earn your first clearance by knowing the words. You earn it by asking the archive the right question.

How to read a complete SELECT
Once a query grows beyond three lines, beginners often get lost. It can look as though SQL runs strictly from top to bottom, in the same order the text appears.
A better way to read it is by logical stages.
For example:
SELECT
name,
category,
price,
CASE
WHEN price < 15 THEN 'cheap'
WHEN price < 40 THEN 'mid-range'
ELSE 'expensive'
END AS segment
FROM products
WHERE category IN ('Books', 'Toys')
AND price BETWEEN 10 AND 30
ORDER BY price DESC, id
LIMIT 5;
You can break this query down step by step.
Start with the source:
FROM products
The database starts with the products table.
Then apply the row filter:
WHERE category IN ('Books', 'Toys')
AND price BETWEEN 10 AND 30
Only products in the Books and Toys categories priced from $10.00 through $30.00, inclusive, remain.
Then look at the columns and calculations:
SELECT
name,
category,
price,
CASE ... END AS segment
The query returns the name, category, and price, and adds a segment with CASE.
Then comes the sort order:
ORDER BY price DESC, id
More expensive products come first. If two products have the same price, id determines their order consistently.
Only after that do we limit the result:
LIMIT 5
That leaves the first five rows after sorting.
The key idea:
LIMITdoesn't choose the “best” rows on its own. It simply takes the first rows from the order you defined withORDER BY.
What makes a query reliable
At this level, getting a green checkmark isn't enough. You also need to understand why the query returned those particular rows.
A reliable query usually has three qualities.
First, it states exactly which rows you want.
The condition shouldn't be something you have to infer from a tangle of logic. A good WHERE clause reads like a precise rule:
WHERE category IN ('Books', 'Toys')
AND price BETWEEN 10 AND 30
Second, it states exactly how the result should be ordered.
If you need the most expensive products, the newest orders, or users first in alphabetical order, write that requirement in ORDER BY:
ORDER BY price DESC, id
Third, it handles uncertainty explicitly.
If the data can contain NULL, account for it directly:
WHERE city IS NULL
or:
WHERE city <> 'Miami'
OR city IS NULL
If some rows in a CASE match none of the branches, decide in advance what should happen to them:
ELSE 'Other status'
If rows with equal values need a stable order, add a unique key as a tiebreaker:
ORDER BY price DESC, id
In small practice tables, many flaws are easy to miss. In a real database, those details can create silent errors: the query runs successfully, but the result is wrong.
Silent errors: when a query runs but lies
The most troublesome SQL mistakes don't always appear as syntax errors.
More often, the query runs and returns a table, but the rows aren't the ones you intended.
Consider a comparison with NULL:
WHERE city = NULL
The query may be syntactically valid, but it won't find rows where the city is missing. To test for NULL, use:
WHERE city IS NULL
Or consider a condition that mixes AND and OR:
WHERE category = 'Books'
OR category = 'Toys'
AND price < 30
At a glance, you might read this as:
Books or Toys, with a price below $30.00
But SQL evaluates AND before OR, so the actual logic is different:
WHERE category = 'Books'
OR (category = 'Toys' AND price < 30)
If you want the price condition to apply to both categories, add parentheses:
WHERE (category = 'Books' OR category = 'Toys')
AND price < 30
Or write it more cleanly:
WHERE category IN ('Books', 'Toys')
AND price < 30
Another silent error is a CASE without an ELSE:
CASE
WHEN status = 'paid' THEN 'Payment received'
WHEN status = 'pending' THEN 'Awaiting payment'
END AS status_label
If a cancelled status appears, its label will be NULL. Sometimes that's acceptable, but in a report it's often better to provide an explicit fallback:
ELSE 'Other status'
Finally, consider LIMIT without ORDER BY:
SELECT name, price
FROM products
LIMIT 5;
This query doesn't return a top 5. It returns whichever five rows happen to come first in the order the database chooses to return them.
A top list needs a criterion:
SELECT name, price
FROM products
ORDER BY price DESC, id
LIMIT 5;
Silent errors are dangerous because the database doesn't object. It executes exactly what you wrote, even if you meant something else.
QUERY: The archive doesn't read intentions. It reads the query. If your idea isn't written explicitly, it doesn't exist.
Before you submit a query
Before you submit a solution in the practice environment, give your query a quick review.
First, check that you selected exactly the columns the task asks for.
If the task requests:
name, price
don't leave this in your final query:
SELECT *
It may be convenient while drafting, but the final answer should return exactly what the task asks for.
Then check the filter.
If the task says “from $10.00 through $30.00, inclusive,” this is a good fit:
BETWEEN 10 AND 30
If it says “category is Books or Toys,” this is easier to read:
IN ('Books', 'Toys')
If you need “starts with C,” use:
LIKE 'C%'
If you need “contains C,” use:
LIKE '%C%'
But remember: a leading % can be expensive on large tables.
Next, check NULL.
If you need to find a missing value, don't write:
= NULL
Write:
IS NULL
If you need to exclude a value while keeping rows with NULL, make that explicit:
WHERE city <> 'Miami'
OR city IS NULL
Then check the sort order.
If the task contains words like:
most expensive
cheapest
latest
first
top
you almost certainly need ORDER BY.
If the task limits the number of rows, you almost certainly need LIMIT.
Finally, if you're sorting by a column that can contain equal values, add a unique key:
ORDER BY price DESC, id
That keeps the result stable.
What you can do by the end of this module
This module was about selecting rows.
You're not calculating revenue, average order value, or order counts by group yet—that comes at the next level. But you already know how to pull exactly the slice of data you need from a table to answer a question.
You now know the basic path:
SELECT ...
FROM ...
WHERE ...
ORDER BY ...
LIMIT ...
You understand why are useful:
price * stock AS stock_value
You know how to work with missing values:
IS NULL
IS NOT NULL
COALESCE(...)
You know how to write concise filters:
BETWEEN
IN
LIKE
You know how to get a list of distinct values:
SELECT DISTINCT status
FROM orders;
You know how to add human-readable labels to the output:
CASE
WHEN ... THEN ...
ELSE ...
END
You also know that correct syntax doesn't guarantee correct logic.
SQL can execute a query perfectly and still return the wrong result if the condition doesn't express what you actually meant.
Interview question
Interview question:
A query is syntactically correct, but rows quietly disappear from the output or get the wrong values. What are some common causes?
Strong answer:
A common cause is incorrect handling of NULL. Comparisons with =, <>, and some uses of NOT IN can produce UNKNOWN when NULL is involved. Because WHERE keeps only rows for which the condition is TRUE, rows can disappear without an error. To work with NULL, use IS NULL, IS NOT NULL, and sometimes COALESCE or IS DISTINCT FROM in PostgreSQL.
Another cause is mixing AND and OR without parentheses. AND has higher precedence, so SQL may group the condition differently from the way a person reads it. If the logic isn't obvious, add parentheses explicitly.
A third cause is an incomplete CASE. If no WHEN matches and there's no ELSE, the result is NULL. In the simple form, CASE x WHEN NULL THEN ... won't match either, because it works like comparing with x = NULL.
A fourth cause is using LIMIT without ORDER BY. That doesn't return rows that are “first” in any meaningful sense; it simply returns some number of rows in an undefined order. Top lists and pages need an explicit ORDER BY, and stable results when values tie need an additional sort by a unique key.
In an interview, don't stop at listing these cases. Show that you write defensively: handle NULL explicitly, use parentheses in mixed conditions, add an ELSE to CASE, and don't treat LIMIT as a substitute for sorting.
QUERY: From here on, the archive opens only to those who can calculate. Revenue, average order value, groups—that's the next level of clearance.