I have a query in which I want to select all the customers who have orders with a particular product_id(say 12,13). I have made a fiddle for this. There is an orders table which contains the order_id and customer_id. Order_detail table has order_id and product_id. These are the sample tables. Original tables contain more than 30000 records. Could you please help me in optimising the queries or guide me the way to do so?
Optimizing SQL query?
62 Views Asked by Sunil Garg At
2
You can use below final query-
Note: Below fields should be indexed - customer_id IN orders TABLE order_id AND product_id IN order_detail TABLE