MAX()() — SQL Technical Interview Questions & Answers
MAX()()
MAX()()
- MAX(marks) highest value. Topper query: ORDER BY marks DESC LIMIT 1 or WHERE marks = (SELECT MAX(marks) FROM students). The subquery form keeps ties.
- LIMIT 1 hides ties. Say that in the interview.
- Trap: MAX without mentioning ties.
- On the example next to this theory: MAX()() — aggregate functions collapse many rows into one summary row.
Technical Interview Tip: MAX(marks). Ties: WHERE marks = (SELECT MAX(marks) FROM students).
Code Examples for MAX()()
MAX()() — sample query
CREATE TABLE scores (id INTEGER PRIMARY KEY, marks INTEGER);
INSERT INTO scores VALUES (1, 80), (2, 90), (3, 70);
SELECT COUNT(*) AS n, AVG(marks) AS avg_marks, MAX(marks) AS top
FROM scores;MAX()() — aggregate functions collapse many rows into one summary row.
How to Explain MAX()() to an Interviewer
All toppers, not one?
WHERE marks = (SELECT MAX(marks) FROM students)