🔍 Data Query Language (DQL)
Last Updated: 7th January 2026
Data Query Language (DQL) is a part of SQL used only to retrieve data from a database. It does not modify the data — it only queries (asks) the database.
- DQL is mainly based on the
SELECTcommand - It is used to:
- fetch data
- filter data
- sort data
- group data
Hinglish Tip 🗣: DQL ka kaam sirf data dekhna aur nikalna hota hai, data change karna nahi.
🧾 Core DQL Command
SELECT
SELECT * FROM students;
- This query fetches all columns
- From the
studentstable
⚠️ SELECT is the only command in pure DQL.
🧩 Clauses Used with DQL
DQL becomes powerful when combined with SQL clauses.
| Clause | Purpose (High Level) |
|---|---|
| SELECT | Choose columns |
| FROM | Choose table |
| WHERE | Filter rows |
| GROUP BY | Group rows |
| HAVING | Filter grouped data |
| ORDER BY | Sort result |
| LIMIT / OFFSET | Restrict rows |
| JOIN | Join multiple tables |
Note: We Wil Cover Each Clause In Upcoming Tutorials
🔢 Clause Order Matters (Very Important)
SQL clauses must follow a fixed logical order. Changing the order can cause errors or wrong results.
| Order | Clause |
|---|---|
| 1 | SELECT |
| 2 | FROM |
| 3 | JOIN |
| 4 | WHERE |
| 5 | GROUP BY |
| 6 | HAVING |
| 7 | ORDER BY |
| 8 | LIMIT / OFFSET |
Example Showing Clause Order
SELECT department, AVG(salary)
FROM employees
WHERE salary > 30000
GROUP BY department
HAVING AVG(salary) > 40000
ORDER BY AVG(salary) DESC
LIMIT 5;
👉 Focus here is order, not logic. Each clause appears in its correct position.