SQL
All Top 50 SQL Interview Questions#14
Cartesian Products with CROSS JOIN in SQL
MediumInterview Question #14
Given `stores` (store_id, city) and `products` (product_id, sku), write a SQL query to generate a complete matrix of all possible store-product combinations to audit stocking gaps.
Input Table: stores & products
2 rows preview| store_id | city | product_id | sku |
|---|---|---|---|
| 1 | Gurgaon | 101 | SKU-A |
| 2 | Bangalore | 102 | SKU-B |
Expected Output Structure4 rows
| store_id | city | product_id | sku |
|---|---|---|---|
| 1 | Gurgaon | 101 | SKU-A |
| 1 | Gurgaon | 102 | SKU-B |
| 2 | Bangalore | 101 | SKU-A |
| 2 | Bangalore | 102 | SKU-B |
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.