Code of the Day
BeginnerQuerying basics

SELECT and columns

Choose exactly the columns you want, rename them, and remove duplicates.

SQLBeginner7 min read
Recommended first
By the end of this lesson you will be able to:
  • 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:

SQL — editable, runs in your browser

Choosing columns (called projection) keeps results focused and is clearer than * for anything beyond a quick look on a .

Renaming with AS

Give an output column a friendlier name with AS — useful for computed values:

SQL — editable, runs in your browser

You can compute columns too. Prices are per-item; here's each product with a "price in pence":

SQL — editable, runs in your browser

Removing duplicates with DISTINCT

DISTINCT collapses identical rows to one — handy for "what are the distinct values?":

SQL — editable, runs in your browser

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 rowsfiltering with WHERE.

Finished reading? Mark it complete to track your progress.

On this page