SQLSQL
#16

Multi-Key and Range Condition Joins in SQL

Medium
Interview Question #16

Given `promotions` (promo_code, start_date, end_date, discount_pct) and `orders` (order_id, promo_code, order_date), write a query to join orders with their applicable promotion, verifying that `order_date` falls within `start_date` and `end_date`.

Input Table: orders & promotions
2 rows preview
order_idpromo_codeorder_datestart_dateend_date
1DIWALI502026-10-202026-10-152026-10-25
2DIWALI502026-11-052026-10-152026-10-25
Expected Output Structure1 rows
order_idpromo_codediscount_pct
1DIWALI5050
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us