First questions to the data · Lesson 2 of 20
SELECT: choosing columns
Specific columns, new names with AS, calculations, and DISTINCT.
Instead of *, list just the columns you need, separated by ,. The order you write them is the order they appear.
SELECT name, xp FROM students;
Calculations and new names
You can calculate inside SELECT itself; the result is a new column that isn't stored in the table. AS gives it a clear name (an alias).
SELECT title,
price,
price * 0.8 AS sale_price,
hours * 60 AS minutes
FROM courses;FROM courses: every row
For each row: compute price * 0.8
Return only the columns you asked for
DISTINCT: no repeats
SELECT DISTINCT city FROM students;
Complete the code
Complete the query so each city appears only once.
SELECT city FROM students;
Quick question
How many rows does SELECT DISTINCT city FROM students return? (Cities: Cairo ×3, Alexandria ×2, Giza ×2, Mansoura ×1)
Exercise
Show title and hours for every course, but name the hours column duration.
title | duration HTML & CSS | 12 JavaScript | 30 Python | 28 SQL | 16 React | 24 C++ | 36
SELECT title FROM courses;
Learn more from
Played 0 of 3 games
Sign in to save your progress and earn XP.