CodeBlanks Logo Icon CodeBlanks

Selecting specific columns

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

query.sql
-- write three columns
SELECT
FROM customers

Sample solution

query.sql
SELECT name, email, city
FROM customers

Expected 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

Question
SELECT name,____
FROM customers;
Answer
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.

All lessons in Beginner