0
0
SQLquery~10 mins

Date range overlap detection in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select all records where the start date is before the end date.

SQL
SELECT * FROM events WHERE start_date [1] end_date;
Drag options to blanks, or click blank then click option'
A<
B>=
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' reverses the date order.
Using '=' allows zero-length ranges which may not be valid.
2fill in blank
medium

Complete the code to find overlapping date ranges between two tables on the start date.

SQL
SELECT a.id, b.id FROM bookings a JOIN reservations b ON a.start_date [1] b.end_date;
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' excludes cases where dates touch exactly.
Using '>' misses overlaps where start is before end.
3fill in blank
hard

Fix the error in the overlap condition to correctly detect overlapping date ranges.

SQL
SELECT * FROM periods WHERE NOT (period_end [1] period_start2 OR period_end2 [1] period_start);
Drag options to blanks, or click blank then click option'
A>
B<=
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '>=' reverses the logic and causes wrong results.
Using '<' misses cases where periods touch exactly.
4fill in blank
hard

Fill both blanks to complete the query that finds overlapping date ranges between two tables.

SQL
SELECT a.id, b.id FROM events a JOIN events b ON a.start_date [1] b.end_date AND a.end_date [2] b.start_date WHERE a.id != b.id;
Drag options to blanks, or click blank then click option'
A<=
B>=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' in the first blank reverses the logic.
Using '<=' in the second blank misses overlaps where dates touch.
5fill in blank
hard

Fill all three blanks to write a query that detects overlapping date ranges and selects their IDs.

SQL
SELECT a.[1], b.[2] FROM schedules a JOIN schedules b ON a.[3] < b.end_date AND a.end_date >= b.start_date WHERE a.[1] != b.[2];
Drag options to blanks, or click blank then click option'
Aschedule_id
Bid
Cstart_date
Devent_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using different ID columns for a and b causes errors.
Using wrong date columns breaks the overlap logic.