SQL
All Top 50 SQL Interview Questions#5
Distinct Location Tracking with DISTINCT vs GROUP BY in SQL
EasyInterview Question #5
From a `shipments` table, find all unique combinations of `origin_hub` and `destination_city` where shipment status is 'Completed'.
Input Table: shipments
4 rows preview| shipment_id | origin_hub | destination_city | status |
|---|---|---|---|
| S1 | Delhi Hub | Jaipur | Completed |
| S2 | Delhi Hub | Jaipur | Completed |
| S3 | Mumbai Hub | Pune | Completed |
| S4 | Delhi Hub | Agra | In Transit |
Expected Output Structure2 rows
| origin_hub | destination_city |
|---|---|
| Delhi Hub | Jaipur |
| Mumbai Hub | Pune |
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.