Lesson 2 of 10 · 30 min
Classic beginner interview questions
By the end of this lesson you can solve the six classic screening questions (second highest value, duplicate detection, counts that include empty groups, did-X-but-not-Y, employee-versus-manager self-joins and distinct counts per period) and explain the trap each one hides.
Screening questions look easy, and that is the point: the interviewer is checking whether you notice the one detail that makes the obvious answer wrong. This lesson moves between three datasets (Masar Holding HR in people, Wadi Market in shop and Shifa Clinics in clinic) so you also practise orienting yourself in a new schema within a minute.
For each pattern, learn three things: the shape of the solution, the trap, and the sentence you say to show you saw the trap.
1. Nth highest value
“What is the second-highest salary?” The trap is duplicates at the top. ORDER BY salary DESC LIMIT 1 OFFSET 1 returns the second row, which is the highest value again if two rows share it. Ask: “Second-highest distinct value, or second row?” Usually it is the distinct value.
This lesson, its 6 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons