Bird
0
0

Consider tables Orders(order_id, order_date) and DeliveryWindows(window_id, start_date, end_date). What does this query return?

medium📝 query result Q5 of 15
SQL - Advanced Joins
Consider tables Orders(order_id, order_date) and DeliveryWindows(window_id, start_date, end_date). What does this query return?
SELECT o.order_id, d.window_id FROM Orders o JOIN DeliveryWindows d ON o.order_date >= d.start_date AND o.order_date <= d.end_date;
AOrders with order_date exactly equal to start_date or end_date only.
BAll orders matched with all delivery windows regardless of dates.
COrders matched with delivery windows where order date falls within the window.
DQuery will fail due to multiple conditions in JOIN.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze join condition with AND

    Join matches orders where order_date is between start_date and end_date inclusive.
  2. Step 2: Understand result

    Returns order IDs with delivery window IDs where order date fits the window range.
  3. Final Answer:

    Orders matched with delivery windows where order date falls within the window. -> Option C
  4. Quick Check:

    Non-equi join with AND conditions returns matching ranges [OK]
Quick Trick: Use AND to combine range conditions in non-equi joins [OK]
Common Mistakes:
MISTAKES
  • Assuming query returns all combinations
  • Thinking multiple conditions cause syntax error
  • Believing only exact matches are returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes