[thelist] SQL replace subquery with join

Bill Moseley moseley at hank.org
Tue Jan 5 11:13:59 CST 2010


On Tue, Jan 5, 2010 at 7:56 AM, Jason Handby <jason.handby at corestar.co.uk>wrote:

> Your version using IN looks fine to me, anyway, what's wrong with doing
> it that way?
>

Not really.  I'm using an ORM and not using the subquery would make life
easier.

I think what I wrote was incorrect, though.  Probably should have been:

SELECT cd.*
FROM cd
WHERE NOT EXISTS  (
    SELECT NULL FROM genre g WHERE g.cd = cd.id AND g.name = 'rock'
)

But, I suppose that might depend on how the database optimizes the query.



-- 
Bill Moseley
moseley at hank.org


More information about the thelist mailing list