In SQL, why is "Distinct" not used in a subquery, when looking for some items "not showing up" in th
Posted
by Jian Lin
on Stack Overflow
See other posts from Stack Overflow
or by Jian Lin
Published on 2010-04-24T14:54:46Z
Indexed on
2010/04/24
15:03 UTC
Read the original article
Hit count: 202
Usually when looking for some items not showing up in the other table, we can use:
select * from gifts where giftID not in (select giftID from sentgifts);
or
select * from gifts where giftID not in (select distinct giftID from sentgifts);
the second line is with "distinct" added, so that the resulting table is smaller, and probably let the search for "not in" faster too.
So, won't using "distinct" be desirable? Often than not, I don't see it being used in the subquery in such a case. Is there advantage or disadvantage of using it? thanks.
© Stack Overflow or respective owner