Loading…
This nested query is hard to read:
SELECT * FROM customers
WHERE id IN (
SELECT customerId FROM orders
WHERE id IN (
SELECT orderId FROM orderItems
WHERE productId IN (
SELECT id FROM products WHERE category = 'Electronics'
)
)
);
Refactor this to use CTEs! Create:
electronics_products - IDs of Electronics productselectronics_orders - Order IDs containing electronicselectronics_customers - Customer IDs who ordered electronicsThen select customer name and email from your final CTE joined with customers.
Downloading SQL engine… (one-time)
This runs entirely in your browser and is cached for next time.