Brightlane's clearance team is running a 10% discount event on products that have not yet been assigned to a product category.
Write a query to return each uncategorized product's name, its original price, and its clearance price.
Assumptions:
- The
productstable contains every item in Brightlane's catalog. - The
category_idcolumn links each product to its category; products awaiting classification havecategory_idset toNULL. - The clearance price is the original price multiplied by 0.9 (a 10% reduction).
Output:
- One row per uncategorized product, with columns
name,price, andclearance_price.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
price,
price * 0.9 AS clearance_price
FROM
products
WHERE
category_id IS NULL The shape
WHERE decides which rows survive; SELECT decides what each surviving row looks like. The clearance event needs uncategorized products (filter on category_id IS NULL) with the 10% discount applied (compute price * 0.9 inline).
Clause by clause
SELECT name, price, price * 0.9 AS clearance_pricereturns three columns per surviving row: the product's name, its current price, and the discounted price computed on the fly.price * 0.9runs once per row, so theMystery Bundleat29.99lands at26.991andGift Card $50lands at45.AS clearance_pricelabels the derived column so the team reads the result as a price list.FROM productsreads the catalog.WHERE category_id IS NULLkeeps only products whose category link is absent — the items awaiting classification.
Why this and not compute first, then filter
WHERE runs before SELECT, so price * 0.9 only ever evaluates against the three rows that passed the IS NULL check. The categorized products never get the multiplication done on them; they're already gone by the time the SELECT list runs.
This ordering is also why an alias defined in SELECT can't be referenced from WHERE — the alias doesn't exist yet when WHERE runs.
The trap
WHERE category_id = NULL returns zero rows, the SELECT list never runs against anything, and the clearance event launches with no products on it. = against NULL evaluates to unknown, never true. IS NULL is the only operator that detects absence.
You practiced filtering on IS NULL while computing a derived column in the same query. Filter-and-compute is the everyday shape — WHERE decides which rows pass through, SELECT decides what each row looks like.