Duplicate:
How to choose Select aa Select
I have 2 tables:
TABLE1 Table1Id TABLE2 Table2Id Table1Id UserId
TABLE2 contains thousands of records. I want to return a list of TABLE1 entries, where there is no entry in TABLE2 for it for a specific user. So, if there is no foreign key entry in table 2. Type request:
select count(*) from TABLE1 where Table1Id not in ( select Table1Id from TABLE2 where id_user = 1)
However, this query is very slow. What will be the most effective way to get the desired results?
sql tsql
Jon Archway Apr 17 '09 at 16:07 2009-04-17 16:07
source share