ORDER BY salary DESC
LIMIT 5;
Mistake 3 — Forgetting that LIMIT applies after sorting
For a top-N analysis, think:
ORDER BY → LIMITnot simply:
LIMIT → assume top records🔹 Interview Questions
1. What is LIMIT?
LIMIT restricts the number of rows returned by a query.
2. How do you find the top 10 salaries?
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;
3. Can LIMIT be used with WHERE?
Yes.
SELECT *
FROM employees
WHERE department = 'Finance'
LIMIT 5;
4. Why is ORDER BY important when using LIMIT?
Because without sorting, the returned rows are not necessarily the highest, lowest, newest, or oldest records you want.
5. What is OFFSET used for?
OFFSET skips a specified number of rows before returning the requested rows, commonly for pagination.
🎯 Double Tap ❤️ For More