How Does the SELECT Statement Work in SQL?
Learn how the SQL SELECT statement retrieves data: projection, FROM, WHERE, ORDER BY and LIMIT explained with a clear example and interview-ready tips.
Expected Interview Answer
The SELECT statement retrieves rows and columns from one or more tables, letting you choose exactly which fields to return and, optionally, how to filter, group, and order the results.
A SELECT names the columns in the projection list and the source in the FROM clause; the database reads matching rows and returns a result set. It is declarative — you describe what data you want, not how to fetch it, and the query engine plans the access path. Clauses like WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT refine which rows appear and in what shape and order.
- Reads data without modifying it
- Projects only the columns you need
- Supports filtering, sorting, and aggregation
- Works across joined tables
- Declarative and portable across engines
AI Mentor Explanation
Think of asking a scorer for a printout that shows only the batter names and their runs from today's match, ignoring bowling figures and extras. You state the columns you want and the match to read from, and the scorer hands back exactly those figures. A SELECT works the same way: you name the fields and the table, and the database returns just that slice of the scorecard.
Step-by-Step Explanation
Step 1
Name the columns
List the fields you want in the projection, or use * to return every column.
Step 2
Choose the source
Specify the table (or joined tables) in the FROM clause the rows come from.
Step 3
Filter rows
Add an optional WHERE clause so only rows meeting a condition are returned.
Step 4
Shape the output
Use GROUP BY, HAVING, ORDER BY, and LIMIT to aggregate, sort, and cap results.
Step 5
Read the result set
The engine plans an access path and returns matching rows as a table.
What Interviewer Expects
- Knows SELECT is read-only and returns a result set
- Can name the core clauses and their order
- Understands projection vs filtering
- Distinguishes SELECT * from explicit column lists
- Explains it declaratively, not procedurally
Common Mistakes
- Thinking SELECT modifies the underlying data
- Always using SELECT * instead of naming needed columns
- Confusing WHERE with HAVING
- Forgetting ORDER BY does not run before LIMIT chooses rows in some mental models
- Assuming result rows come back in a guaranteed order without ORDER BY
Best Answer (HR Friendly)
“SELECT is the SQL command you use to read data from a database. You tell it which columns you want and which table to look in, and it hands back the matching rows without changing anything.”
Code Example
SELECT first_name, last_name, salary
FROM employees
WHERE department = 'Sales'
ORDER BY salary DESC
LIMIT 10;Follow-up Questions
- What is the logical order of execution of SQL clauses?
- Why is SELECT * discouraged in production queries?
- How does DISTINCT change what SELECT returns?
- What is the difference between WHERE and HAVING?
- How does LIMIT interact with ORDER BY?
MCQ Practice
1. Which clause specifies the table a SELECT reads from?
The FROM clause names the source table (or tables) that the SELECT retrieves rows from.
2. What does a SELECT statement return?
SELECT is read-only; it produces a result set of rows and columns without changing stored data.
3. Which clause guarantees the order of returned rows?
Without ORDER BY, row order is not guaranteed; ORDER BY sorts the result set explicitly.
Flash Cards
What does SELECT do? — Retrieves rows and columns from one or more tables as a read-only result set.
Which clause names the source table? — The FROM clause.
SELECT * vs explicit columns? — * returns all columns; naming columns returns only what you need and is faster and clearer.
How do you sort results? — Use ORDER BY; without it, row order is not guaranteed.