5.3 DQL — SELECT
Level: 5 | Version: v1.1 | Author: Meptrasoft
Overview
SELECT is used to retrieve data from a database.
It can return all columns, specific columns, or only rows that match a condition.
SELECT
↓
FROM
↓
WHERE
↓
RESULT
SELECT = Retrieve the data you need.

Practice Table
This topic reuses the employees table from 5.2 DDL.
| emp_id | emp_name | department | salary |
|---|---|---|---|
| 1 | Ravi Kumar | IT | 45000.00 |
| 2 | Anjali Mehta | HR | 38000.00 |
| 3 | Suresh Rao | Finance | 42000.00 |
| 4 | Priya Nair | IT | 50000.00 |
Basic SELECT
To retrieve all columns:
SELECT *
FROM employees;
* means all columns.
SELECT Specific Columns
You can choose only the columns you need:
SELECT emp_name, department
FROM employees;
Result:
| emp_name | department |
|---|---|
| Ravi Kumar | IT |
| Anjali Mehta | HR |
| Suresh Rao | Finance |
| Priya Nair | IT |
This is usually clearer than selecting unnecessary columns.
SELECT with WHERE
WHERE is used to filter rows.
SELECT *
FROM employees
WHERE department = 'IT';
Result:
| emp_id | emp_name | department | salary |
|---|---|---|---|
| 1 | Ravi Kumar | IT | 45000.00 |
| 4 | Priya Nair | IT | 50000.00 |
Simple Idea
FROM → Which table?
SELECT → Which columns?
WHERE → Which rows?
Logical Query Processing Order
The SQL statement is written in one order, but the database conceptually processes its clauses in a different logical order.
A simplified order is:
FROM / JOIN
↓
WHERE
↓
GROUP BY
↓
HAVING
↓
SELECT
↓
ORDER BY
↓
LIMIT
For example, the database first determines the source rows, applies filtering, performs grouping when required, and then produces the selected output.
The order you write SQL and the logical order used to evaluate it are not always the same.
Note: The exact physical execution may differ because the optimizer can choose a different execution plan.
Common Beginner Mistakes
| ✗ Mistake | ✓ Correct Understanding |
|---|---|
SELECT * means select all tables |
It means all columns from the selected source rows |
WHERE chooses columns |
WHERE filters rows |
FROM filters the result |
FROM identifies the source table or tables |
SELECT always returns every row |
WHERE or other clauses can reduce the returned rows |
| SQL always executes exactly in the written order | SQL has a logical processing order, and the optimizer chooses the physical execution plan |
SELECT changes stored data |
SELECT normally retrieves data without modifying it |
Placement Quick Points
SELECT
→ CHOOSE COLUMNS
FROM
→ CHOOSE SOURCE
WHERE
→ FILTER ROWS
SELECTretrieves data.FROMidentifies the source table or tables.WHEREfilters rows.*means all selected columns.- You can select only the columns needed for the result.
- SQL has a logical query-processing order that differs from the written order.
Interview Questions
- What is SELECT?
SELECTis used to retrieve data from a database.- What is the purpose of FROM?
FROMidentifies the table or other data source from which the query retrieves data.- What is the purpose of WHERE?
WHEREfilters rows based on a condition.- What is the difference between SELECT and WHERE?
SELECT → Which columns? WHERE → Which rows?- What is the logical order of processing a query?
A simplified order is:
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT- Does SELECT modify data?
Normally, no.
SELECTretrieves data without changing the stored rows.
Practice & Hands-On Exercises
Using the employees table:
- Display all columns:
SELECT * FROM employees;
- Display only
emp_nameandsalary:
SELECT emp_name, salary FROM employees;
- Display employees from the
ITdepartment:
SELECT * FROM employees WHERE department = 'IT';
- Display employees whose salary is greater than
40000:
SELECT * FROM employees WHERE salary > 40000;
- Display only
emp_namefor employees inHR:
SELECT emp_name FROM employees WHERE department = 'HR';
- Explain the difference between
SELECT *and selecting specific columns. - Identify the roles of
SELECT,FROM, andWHEREin a query.
💡 Tip: Test your queries using the in-browser interactive runner above.
Key Takeaway
SELECT → COLUMNS
FROM → SOURCE
WHERE → ROWS TO KEEP
SELECT is used to retrieve data, while FROM identifies the source and WHERE filters the rows.
End of DQL — SELECT