Bird
0
0

Why does this query fail to detect overlapping date ranges?

medium📝 Debug Q7 of 15
SQL - Advanced Query Patterns
Why does this query fail to detect overlapping date ranges?
SELECT * FROM bookings WHERE start_date < end_date OR end_date > start_date;
AThe column names are swapped
BUsing OR allows non-overlapping ranges to be included
CThe condition is always true for valid dates
DThe query is missing a JOIN to compare two bookings
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition logic

    Using OR means if either condition is true, the row is included, which is too broad.
  2. Step 2: Effect on overlap detection

    This includes rows that do not overlap, so it fails to detect true overlaps accurately.
  3. Final Answer:

    Using OR allows non-overlapping ranges to be included -> Option B
  4. Quick Check:

    OR causes false positives in overlap detection [OK]
Quick Trick: Use AND, not OR, to detect overlap correctly [OK]
Common Mistakes:
  • Using OR instead of AND in overlap condition
  • Assuming any date comparison means overlap
  • Ignoring that condition is too broad

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes