SQLSQL
#14

Cartesian Products with CROSS JOIN in SQL

Medium
Interview 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_idcityproduct_idsku
1Gurgaon101SKU-A
2Bangalore102SKU-B
Expected Output Structure4 rows
store_idcityproduct_idsku
1Gurgaon101SKU-A
1Gurgaon102SKU-B
2Bangalore101SKU-A
2Bangalore102SKU-B
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