Muhammad
Muhammad

Reputation: 29

sql: select not in

how can I rewrite the following query using JOIN

SELECT * 
FROM table1 
WHERE id NOT IN 
( 
    SELECT t1Id 
    FROM table2 
);

Upvotes: 2

Views: 343

Answers (2)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171579

SELECT * 
FROM table1 t1
left outer join table2 t2 on t1.id=t2.id
where t2.id is null

Upvotes: 8

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25390

       SELECT * FROM table1 t1
       WHERE NOT EXISTS( 
        SELECT *
        FROM table2 t2 
        Where t1.Id = t2.t1Id);

Upvotes: 0

Related Questions