SELECT and columns
Choose exactly the columns you want, rename them, and remove duplicates.
- Project specific columns with SELECT
- Rename output columns with AS
- Remove duplicate rows with DISTINCT
SELECT is how you ask for data. SELECT * returns every column; usually you
want only some. List the columns you care about, comma-separated:
Choosing columns (called projection) keeps results focused and is clearer
than * for anything beyond a quick look on a table.
Renaming with AS
Give an output column a friendlier name with AS — useful for computed values:
You can compute columns too. Prices are per-item; here's each product with a "price in pence":
Removing duplicates with DISTINCT
DISTINCT collapses identical rows to one — handy for "what are the distinct
values?":
Without DISTINCT you'd see UK and US twice (two customers each). With it,
each country appears once.
Where to go next
You can pick columns; next, pick rows — filtering with WHERE.