0

I have a MySQL table which is described in the following question. Counting number of ids present in one table which is not presented on another for a particular user The query which I am using is as follows.

SELECT count(*) coincidences
FROM   table1
WHERE  user_id = 12
AND    NOT EXISTS (SELECT 1
                   FROM   table2
                   WHERE  tableid = table1.id
                   AND    user_id = table1.user_id)

This query is taking too much time for considerably bigger table how can I improve the performance of this particular query.

1

table2 needs INDEX(tableid, user_id) (in either order).

If this does not solve the problem, please provide SHOW CREATE TABLE for both tables, plus EXPLAIN SELECT ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.