SELECT — Reading Rows in SQL
Ask for exactly the columns and rows you need
SELECT reads data. List the columns you want (or * for all), name the table, and the engine returns a fresh result table. Selecting only needed columns is faster and clearer than SELECT *, and the result can be filtered (WHERE), sorted (ORDER BY) and summarised (GROUP BY) — SELECT is the backbone everything else builds on.
Choose the columns
SELECT name, department picks specific columns; * means all of them. Explicit lists are faster to read and survive schema changes.
Name the source
FROM employees — one table for now; FROM can also name a joined or nested result later.
Receive a table back
The result is itself a table: same shape every run, orderable, nestable, aggregatable.
Rename outputs with AS
SELECT salary AS monthly_pay — the alias changes the result header only, not the stored data.
Deduplicate with DISTINCT
SELECT DISTINCT department collapses repeated values — covered fully in its own topic.
1SELECT name, department, salary2FROM employees;
| name | department | salary |
|---|---|---|
| Alice | Engineering | 85000 |
| Bob | Sales | 52000 |
| Cynthia | Engineering | 91000 |
| David | Marketing | 47000 |
| Elena | Sales | 58000 |
| Farid | Engineering | 73000 |
All six rows return, but only three of the five columns — projection in action. Swap in * to see everything, or DISTINCT department to collapse duplicates.
SELECT *
Every column, in table-definition order.
1SELECT * FROM employees;
| id | name | department | salary | age |
|---|---|---|---|---|
| 1 | Alice | Engineering | 85000 | 29 |
| 2 | Bob | Sales | 52000 | 35 |
| 3 | Cynthia | Engineering | 91000 | 41 |
| 4 | David | Marketing | 47000 | 38 |
| 5 | Elena | Sales | 58000 | 26 |
| 6 | Farid | Engineering | 73000 | 33 |
Chosen columns
Projection: keep only the columns the question needs.
1SELECT name, department, salary2FROM employees;
| name | department | salary |
|---|---|---|
| Alice | Engineering | 85000 |
| Bob | Sales | 52000 |
| Cynthia | Engineering | 91000 |
| David | Marketing | 47000 |
| Elena | Sales | 58000 |
| Farid | Engineering | 73000 |
Aliased output
AS renames a column in the result header.
1SELECT name AS employee_name,2 salary AS annual_pay3FROM employees;
| employee_name | annual_pay |
|---|---|
| Alice | 85000 |
| Bob | 52000 |
| Cynthia | 91000 |
| David | 47000 |
| Elena | 58000 |
| Farid | 73000 |
Computed columns
Expressions compute a new column per row.
1SELECT name,2 salary * 12 AS annual_pay3FROM employees;
| name | annual_pay |
|---|---|
| Alice | 1020000 |
| Bob | 624000 |
| Cynthia | 1092000 |
| David | 564000 |
| Elena | 696000 |
| Farid | 876000 |
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.