Ho to avoid Not In & In clause in my query
-
select id,name from stud where (id not in (select id from class)) and depid in (select depid from dep where rid=@rid)
-
select id,name from stud where (id not in (select id from class)) and depid in (select depid from dep where rid=@rid)
What about:
Select DISTINCT id, name
FROM stud
INNER JOIN dep on stud.depid=dep.depid
LEFT JOIN class on stud.id=class.id
WHERE dep.rid=@rid
AND stud.id is nullBut I doubt that it's faster...
-
select id,name from stud where (id not in (select id from class)) and depid in (select depid from dep where rid=@rid)
JOIN
/EXISTS
SQL SERVER – Subquery or Join – Various Options – SQL Server Engine knows the Best[^]thatraja
Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
-
select id,name from stud where (id not in (select id from class)) and depid in (select depid from dep where rid=@rid)
-
What about:
Select DISTINCT id, name
FROM stud
INNER JOIN dep on stud.depid=dep.depid
LEFT JOIN class on stud.id=class.id
WHERE dep.rid=@rid
AND stud.id is nullBut I doubt that it's faster...
Im not sure, but compare not in the join will be the faster one, i heared like that :(