SQL
All Top 50 SQL Interview Questions#16
Multi-Key and Range Condition Joins in SQL
MediumInterview 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_id | promo_code | order_date | start_date | end_date |
|---|---|---|---|---|
| 1 | DIWALI50 | 2026-10-20 | 2026-10-15 | 2026-10-25 |
| 2 | DIWALI50 | 2026-11-05 | 2026-10-15 | 2026-10-25 |
Expected Output Structure1 rows
| order_id | promo_code | discount_pct |
|---|---|---|
| 1 | DIWALI50 | 50 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.