Skip to main content
Intermediate~2h

Subqueries & EXISTS in SQL & DatabasesInterview Readiness Check

Correlated vs uncorrelated subqueries, NOT IN with NULLs, EXISTS vs IN performance, LATERAL joins.

subqueryexistsinnot incorrelatedlateralderived table

Learning path

Joins & RelationshipsAggregations & Grouping→Subqueries & EXISTS ← you are here

Try a sample question

Table: page_views(user_id, page, viewed_at). You want users who hit '/checkout' but NOT '/thank-you' in the last 24 hours — they abandoned checkout. Which query is correct and NULL-safe?

A.SELECT DISTINCT user_id FROM page_views WHERE page='/checkout' AND user_id NOT IN (SELECT user_id FROM page_views WHERE page='/thank-you') — silently returns zero rows if any user_id in the subquery is NULL
B.SELECT user_id FROM page_views WHERE page='/checkout' EXCEPT SELECT user_id FROM page_views WHERE page='/thank-you' — ignores the 24-hour window on both sides
C.SELECT DISTINCT user_id FROM page_views WHERE page='/checkout' AND user_id != ALL (SELECT user_id FROM page_views WHERE page='/thank-you') — semantically the same NULL trap as NOT IN
D.SELECT DISTINCT user_id FROM page_views pv WHERE pv.page='/checkout' AND pv.viewed_at > NOW()-INTERVAL '24 hours' AND NOT EXISTS (SELECT 1 FROM page_views p2 WHERE p2.user_id = pv.user_id AND p2.page='/thank-you' AND p2.viewed_at > NOW()-INTERVAL '24 hours') — NULL-safe anti-join, correctly scoped to the 24h window on both sides

Sign up free to take the full check and see the answer with an explanation.

What this module tests

  • Conceptual understanding of subqueries & exists fundamentals
  • Trade-offs and design decisions in real system scenarios
  • subquery and exists — applied knowledge
  • Interview-style reasoning and explanation quality

Free to start

Take the Subqueries & EXISTS check →

10 questions · Dimension scoring · AI coach feedback · Shareable result

Test your knowledge — free →

No credit card · Takes 10–15 min

Frequently asked questions

What does the Subqueries & EXISTS check test?
The check covers correlated vs uncorrelated subqueries, not in with nulls, exists vs in performance, lateral joins. Questions span beginner to advanced difficulty and test both conceptual understanding and practical trade-off reasoning.
What keywords should I know for Subqueries & EXISTS?
Key concepts include: subquery, exists, in, not in, correlated, lateral, derived table. These frequently appear in sql & databases interviews at product and infrastructure companies.
How many questions are in the check?
Each check has 10 questions — a mix of MCQ and short-answer. You get scored by dimension (e.g., scalability, consistency) so you know exactly where to focus.
How long does it take to study Subqueries & EXISTS?
Most engineers spend around 2 hours on this module. The check itself takes about 10–15 minutes. You can retake it up to 3 times per day.
What prerequisite knowledge do I need before Subqueries & EXISTS?
Subqueries & EXISTS builds on Joins & Relationships and Aggregations & Grouping. Complete those first for the best results.
Is subquery, exists, in covered?
Yes. The Subqueries & EXISTS module covers subquery, exists, in among other key concepts. The check includes questions that reflect real sql & databases interview patterns.