Recall & Review
beginner
What does it mean when two date ranges overlap?
Two date ranges overlap if they share at least one day in common. For example, if one range is from Jan 1 to Jan 10 and another is from Jan 5 to Jan 15, they overlap from Jan 5 to Jan 10.
Click to reveal answer
beginner
Write the basic SQL condition to check if two date ranges (start1, end1) and (start2, end2) overlap.
The condition is: start1 <= end2 AND end1 >= start2. This means the first range starts before the second ends, and the first range ends after the second starts.
Click to reveal answer
intermediate
Why do we use <= and >= operators in date range overlap detection instead of < and >?
Using <= and >= includes cases where the ranges touch at the boundary (like one ends on Jan 10 and the other starts on Jan 10). This counts as overlapping because they share that day.
Click to reveal answer
beginner
How can you find all rows in a table 'events' that overlap with a given date range '2024-01-01' to '2024-01-10'?
Use a query like: SELECT * FROM events WHERE start_date <= '2024-01-10' AND end_date >= '2024-01-01'; This returns all events that overlap with the given range.
Click to reveal answer
beginner
What real-life situations require detecting overlapping date ranges?
Examples include booking hotel rooms, scheduling meetings, reserving rental cars, or managing employee shifts. Detecting overlaps helps avoid double bookings or conflicts.
Click to reveal answer
Which SQL condition correctly detects if two date ranges overlap?
✗ Incorrect
The correct condition is start1 <= end2 AND end1 >= start2 because it checks if the ranges share any dates.
If one date range ends on 2024-03-10 and another starts on 2024-03-10, do they overlap?
✗ Incorrect
Using <= and >= includes boundary dates, so they overlap on 2024-03-10.
What will this query return? SELECT * FROM bookings WHERE start_date <= '2024-05-20' AND end_date >= '2024-05-15';
✗ Incorrect
The query finds all bookings that overlap with the date range May 15 to May 20, 2024.
Which of these is NOT a use case for date range overlap detection?
✗ Incorrect
Checking spelling errors is unrelated to date ranges or overlaps.
What happens if you use < and > instead of <= and >= in overlap detection?
✗ Incorrect
Using < and > excludes boundary overlaps, so touching ranges won't count as overlapping.
Explain how to detect if two date ranges overlap using SQL.
Think about when one range starts before the other ends and ends after the other starts.
You got /3 concepts.
Describe a real-world example where detecting overlapping date ranges is important and why.
Consider situations where two people want the same resource at the same time.
You got /3 concepts.