[thelist] SQL replace subquery with join
Jason Handby
jason.handby at corestar.co.uk
Tue Jan 5 11:26:30 CST 2010
> hi bill
>
> try like this --
>
> SELECT cd.*
> FROM cd
> LEFT OUTER
> JOIN genre
> ON genre.cd = cd.id
> AND genre.name = 'rock'
> WHERE genre.name IS NULL
>
> in the ON clause of the outer join, put what you're looking for (i.e.
> looking for rock)
>
> then the WHERE clause filters those out, leaving only the ones that
> aren't
> rock
>
> simple, innit
>
> ;o)
*slaps forehead*
I'd probably still write the subquery version, as I think it looks more
elegant and it more obviously says what it does. At least to me :-)
Jason
More information about the thelist
mailing list