Sam needs every order above £500 from the Electronics category, placed last quarter. In Excel he would filter three columns manually. In SQL he writes one WHERE clause — and it runs against ten million rows in seconds.
The SELECT clause in detail
SELECT controls which columns appear in your results. Use * to get all columns (fine for exploration, bad for production) or list specific column names separated by commas.
SELECT * FROM SalesFact;
-- Specific columns (production queries)
SELECT OrderDate, Salesperson, Revenue FROM SalesFact;
Column aliasing with AS
AS renames a column in the output. It does not rename the column in the database — only in your results.
Salesperson AS "Sales Rep",
Revenue AS "Total Revenue (£)"
FROM SalesFact;
Comparison operators
Combining conditions — AND, OR, NOT
WHERE Region = 'North' AND Revenue > 1000
-- OR: either condition can be true
WHERE Category = 'Electronics' OR Category = 'Furniture'
-- NOT: exclude matching rows
WHERE NOT Region = 'South'
WHERE a = 1 OR b = 2 AND c = 3 is evaluated as a = 1 OR (b = 2 AND c = 3) because AND has higher precedence. Always use brackets when mixing both.The IN operator
IN is a cleaner alternative to multiple OR conditions on the same column.
WHERE Category = 'Electronics' OR Category = 'Furniture' OR Category = 'Sports'
-- With IN (clean)
WHERE Category IN ('Electronics', 'Furniture', 'Sports')
The BETWEEN operator
-- Equivalent to: WHERE Revenue >= 500 AND Revenue <= 2000
Pattern matching with LIKE
WHERE Product LIKE '%Chair%' -- contains Chair
WHERE Product LIKE '%er' -- ends with er
NULL handling
NULL means unknown — not zero, not empty string. You cannot compare to NULL with = — use IS NULL or IS NOT NULL.
WHERE Revenue != NULL -- WRONG — always returns nothing
Write a query that returns all sales from salespersons whose names start with 'P' or 'A', in the Electronics or Sports category, with revenue above 200. Use LIKE, IN, AND, and a comparison operator together.