I have three tables in database Account, Product and Users. Following query that I wrote is taking too long to execute. Is there anyway to optimize this following query?
"SELECT accounts.id AS aucID, accounts.product_id, accounts.end_time, accounts.price, accounts.win_id,
products.id, products.title, products.ratio, users.id , users.username, users.gender, users.email, users.ip
FROM accounts, products, users
WHERE products.id
IN (
SELECT id
FROM products
WHERE accounts.product_id = id
)
AND users.id
IN (
SELECT id
FROM users
WHERE accounts.win_id = id
)
AND accounts.end_time >= '$monday'
AND accounts.end_time < '$sunday'
GROUP BY accounts.end_time"