Selecting specific columns
- SQL course
- Beginner
- Lesson 3/115
- 4 min
Learn to fetch only the columns you want, separated by commas.
Selecting specific columns
Most queries need only a few columns. You list them after SELECT, separated by commas.
SELECT name, email, city
FROM customers;This fetches three columns: name, email and city. Fewer columns mean a faster query and less network load.
name, email, city is selected from customers.
Selecting specific columns — details
The column order in your query sets the order in the result. If you write SELECT name, price then name comes first, then price. You can pick any order; it does not have to match the table. This flexibility lets you arrange reports in a readable order. For example you can put price first, then name; it makes more sense for the reader.
Practice Selecting specific columns
Select the name, email and city columns from customers.
Starter code
-- write three columns
SELECT
FROM customersSample solution
SELECT name, email, city
FROM customersExpected output
name email city Ayşe ayse@mail.com İstanbul Alex alex@mail.com Berlin
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Selecting specific columns: match the terms
| Term | Meaning |
|---|---|
SELECT |
choose columns |
FROM |
table name |
comma |
separate columns |
; |
end query |
2 Separate columns with comma
SELECT name,____
FROM customers;
SELECT name, email
FROM customers;
Explanation: Several columns are separated by commas: SELECT name, email.
3 What separates two columns?
- A period
- A colon
- A comma Correct answer
- A dash
Explanation: Columns are separated by commas.