Section 2 · The SELECT clause

Choosing columns, renaming them, and doing math

SELECT decides which columns come out and what shape they take. It's the verb you'll type in almost every query, so let's make it second nature.

1Pick exactly the columns you want

SELECT * is great for peeking, but naming columns is clearer, faster, and puts them in the order you want. Swap the column list around and run:

Name your columns
reorder them: try "category, name" — the output order follows

2Rename with AS (aliases)

Column names in the result don't have to match the table. AS gives them friendlier labels — essential once you start computing values:

Aliases make output readable
the header row shows your new names

3Compute new columns on the fly

A SELECT item can be an expression, not just a column. Prices with tax, quantities doubled, strings upper-cased — all computed per row. Watch the with_tax column: it doesn't exist in the table, the engine builds it for each row:

Live math · slide the tax rate
drag the slider — the whole column recomputes live
Why 100.0 and not 100? Writing / 100.0 forces decimal math. It's a good habit in real SQL too, where integer division can silently chop off the fraction (10 / 100 becoming 0). ROUND(x, 2) then tidies the result to 2 decimal places.

4DISTINCT — collapse duplicates

How many different categories are there? Run the first query and you'll see "Coffee" three times. Add DISTINCT and the duplicates fold away:

without DISTINCT
with DISTINCT

5Text functions, right in SELECT

You can transform text as it comes out. UPPER, LOWER and LENGTH are the everyday ones:

Reshape the text
more functions on the Advanced page
Your turn — free play Write a query that shows each customer's name and the year length of their name… or anything you like. There's no wrong experiment. The engine will catch mistakes gently.
Blank canvas
Ctrl+Enter runs too
🧠

Checkpoint — SELECT

1. What does AS do in SELECT price AS dollars?
AS is purely a label for the result column. It doesn't change data or filter anything.
2. SELECT DISTINCT category FROM products returns…
DISTINCT removes duplicate output rows, leaving the 3 unique categories.
3. Can a SELECT column be a calculation like price * 2?
SELECT happily computes expressions — math, functions, CASE — and you'll usually give the result a name with AS.
🔓 You're reading a free chapter of SQL — the first two are open.
Unlock the rest of this course with a one-time payment.
Unlock this course →
🔓 See course prices