Answer the question
In order to leave comments, you need to log in
How to speed up a SELECT query with nested queries?
Tell me how you can simplify such a request .. speed up
SELECT
addresses.*,
accounts.id_account,
accounts.name as name_account,
clients_addresses.id_client as on_client,
clients.name
FROM addresses
LEFT JOIN accounts
ON accounts.id_account = addresses.id_account
LEFT JOIN clients_addresses
ON clients_addresses.id_address = addresses.id_address
LEFT JOIN clients
ON clients_addresses.id_client = clients.id_client
WHERE
addresses.id_project = 10
AND addresses.id_address NOT IN (
SELECT id_address FROM clients_addresses WHERE id_address = addresses.id_address
)
AND addresses.id_account = 65
GROUP BY addresses.id_address
ORDER BY address desc
LIMIT 0,100
Answer the question
In order to leave comments, you need to log in
This:
AND addresses.id_address NOT IN (
SELECT id_address FROM clients_addresses WHERE id_address = addresses.id_address
)
SELECT
a.*,
accounts.id_account,
accounts.name as name_account,
clients_addresses.id_client as on_client,
clients.name
FROM
(SELECT
*
FROM addresses
WHERE id_project = 10
AND id_account = 65
) a
LEFT JOIN ....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question