[thelist] Selecting two distincts
Joel Canfield
joel at spinhead.com
Mon May 6 15:02:00 CDT 2002
Thanks! I'll read up on 'UNION' and see where I can use it. But you're
right, two separate queries would be better.
joel
> You should indeed leave it as two queries. The combination
> would probably use a simple union. What you could do is :
>
> (SELECT 'Genre' AS Type, DISTINCT(g.GenreName) AS Name
> FROM loggenretlk as lg
> JOIN
> genre as g
> ON g.GenreID = lg.GenreID
> JOIN weblog as w
> ON w.LogID = lg.LogID
> WHERE w.LogID = @LogID)
>
> UNION
>
> (SELECT 'Band' AS Type, DISTINCT(b.BandName) AS Name
> FROM logbandtlk as lb
> JOIN
> bands as b
> ON b.BandID = lb.BandID
> JOIN weblog as w
> ON w.LogID = lb.LogID
> WHERE w.LogID = @LogID)
>
> which would give
> Type Name
> Band Band 1
> ...
> Band Band x
> Genre Genre 1
> ...
> Genre Genre x
>
> GL,
> Michiel Trimpe
>
More information about the thelist
mailing list