In my MySQL database I have two tables: ‘orders’ and ‘orders_lines’. Orders contains info about the customer, order date, and so on. Orders_lines contains data about the oredered products, like product_id, price, quantity, tax rate, and so on.
I’m currently building a search-page in which I’d like to return the orders that contain a specific product. For example, I’d like to return all orders with product_id 2. I thought of a query like:
SELECT * FROM orders WHERE order_id IN ( SELECT order_id FROM orders_lines WHERE product_id = 2 )
But when I executed the query this morning I had to call the hosting provider to terminate the MySQL processes because it was way to heavy. Never heard of it and could not figure out why, and I’m pretty desperate at the moment. The orders table contains about 30.000 rows, the orders_lines table about 38.000 rows.
Any suggestions why my database crashes, how to change the query to make it work correctly or how to achieve my goal of displaying orders that contain a certain product are welcome!
Kind regards,
Martijn
I’m not sure this is what you need, anyway try: