Selecting all columns
- SQL course
- Beginner
- Lesson 2/115
- 4 min
Learn to fetch every column with SELECT *.
Selecting all columns
To fetch all columns from a table you use the * wildcard. It is a shortcut instead of listing every column.
SELECT *
FROM customers;This returns every column and every row from the customers table. Handy for a quick look but slow on big tables.
All columns are selected from customers.
Selecting all columns — details
SELECT * looks easy but use it with care in production. Three reasons:
- Adding a column changes what the query returns
- Unneeded columns increase network traffic
- The plan loses selectivity
Best practice: name only the columns you need. SELECT * is fine when you explore a table; for APIs or reports, listing only the needed columns is safer and faster.
Practice Selecting all columns
Write a query that fetches all columns from the customers table.
Starter code
-- select all columns
SELECT
FROM customersSample solution
SELECT *
FROM customersExpected output
id name city 1 Ayşe İstanbul 2 Alex Berlin
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 All columns
SELECT ____
FROM customers;
SELECT *
FROM customers;
Explanation: * selects every column of the table.
2 Which character fetches all columns?
- %
- * Correct answer
- &
- #
Explanation: * selects all columns.
3 Selecting all columns: match the terms
| Term | Meaning |
|---|---|
* |
all columns |
FROM |
table |
comma |
separate columns |
; |
end query |