DISTINCT, expressions & aliases

Choose useful columns

Lesson 2 of 20 · 8 min · Module 1: Read & shape results

A query can shape raw records into a clearer result. Select only the fields that answer the question, and give calculated values useful names.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Select only relevant columns
  • Remove duplicate result rows
  • Distinguish a calculated result from stored data

The idea

DISTINCT removes duplicate result rows. AS gives a result column an alias. Expressions such as xp + 25 calculate a value without updating the stored record.

SELECT name, xp + 25 AS next_xp
FROM learners;

01Think about result rows

DISTINCT applies to the whole selected row. Selecting language alone removes repeated languages; selecting language and name would preserve different name/language pairs.

02Give calculations a readable name

An alias changes the column label in the result. It does not rename the underlying table column or update a stored value. That distinction matters when reading reports.

Your turn

Select each distinct language from learners, in alphabetical order. Return one column and no duplicate rows.

What the checks look for

  • Returns JavaScript, Python, and SQL once each
Try it in the editor →

Take this with you

The selected columns define the shape and meaning of your result.

Learn SQL Foundations for free

20 short lessons with real code and instant checks.

See the whole course →