I’m working with two large tables in MySQL, and I’m trying to retrieve data using a JOIN query. However, the query is taking a long time to execute, especially when the dataset grows. Here’s the query I’m running:
Code
SELECT users.name, orders.order_date, orders.total
FROM users
JOIN orders ON users.id = orders.user_id
WHERE orders.total > 100;
Both tables have over 1 million rows, and I’ve indexed the user_id column in the orders table, but the performance is still slow. Are there any other optimizations I can apply to speed this up?
I tested this query using an online SQL compiler (SQLCompiler.live) for MySQL, which is useful for running queries quickly without setting up a local environment, but I’d like to know how I can optimize it in a real production setting.
Any tips or advice would be appreciated!
You need to sign in to view this answers
Leave feedback about this