SQL Query Puzzle
Three hard SQL scenario and reasoning questions that test query design, set logic, and performance-aware thinking. Reveal the answer after each prompt.
Try this quiz
Play through the questions and see your score instantly
Ready to test your knowledge?
3 questions · Quick play · Instant results
Make your own quiz videos
Turn any topic into a polished video quiz — with AI-powered questions, voiceover, and animations. No video editing skills needed.
Unlimited quizzes, free to start
Create as many quizzes as you want. Describe your topic and AI builds the questions, answers, and explanations for you.
Customise everything
Pick from stunning templates, tweak colours and fonts, add your branding, and choose between vertical or landscape formats.
Export-ready videos
Download HD videos optimised for TikTok, YouTube Shorts, Instagram Reels, or full-length YouTube — one click, no editing.
No credit card required
Quiz Questions & Answers
Review every prompt, the correct responses, and helpful context to prep for your own run-through.
Question 1: When combining two large tables A and B where you need rows present in A but not in B by a key column, which approach is most robust for avoiding incorrect results when NULLs may appear in the key?
Use LEFT JOIN with explicit IS NULL on B.key (A LEFT JOIN B ON A.key = B.key WHERE B.key IS NULL)
Question 2: You must compute each user's rank by score within country, allowing ties to share the same rank and gaps after ties. Which window function achieves this ranking behavior?
Use RANK() OVER (PARTITION BY country ORDER BY score DESC)
Question 3: Given a query that aggregates millions of rows and uses DISTINCT inside COUNT(DISTINCT col), which refactor often improves performance while preserving correctness?
Pre-aggregate distinct values in a derived table (SELECT col FROM table GROUP BY col) then join or count that smaller set