Duplicate:
I have 2 tables:
TABLE1 Table1Id TABLE2 Table2Id Table1Id UserId
TABLE2 has thousands of entries in it. I want to return a list of TABLE1 entries where there isn’t an entry in TABLE2 for it for a particular user. So, where there isn’t a foreign key entry in TABLE2. A query like:
select count(*) from TABLE1 where Table1Id not in ( select Table1Id from TABLE2 where id_user = 1)
However, that query runs very slowly. What would be the most efficient way of getting the results I require?
There is a similar question
I think it would be better
I would check the indexes also, as ck suggested