MyMisPal
← SQL lessons
Lesson 2 of 12

SELECT: choosing columns

Instead of *, list the columns you want separated by commas. It is clearer and faster, especially on big tables.

SQL
SELECT first_name, last_name, job_title
FROM employees;

You can rename a column with AS, and calculate directly:

SQL
SELECT first_name AS name,
       salary,
       salary * 12 AS yearly_salary
FROM employees;

And DISTINCT removes duplicates from the result:

SQL
SELECT DISTINCT category FROM products;

Exercises

Exercise 1

Show first_name, job_title and salary for every employee.

Exercise 2

Show the distinct country values of customers.

Spotted a mistake on this page, or have an idea to improve the site?