[thelist] Selecting two distincts

Michiel Trimpe M.B.Trimpe at student.tue.nl
Mon May 6 14:49:01 CDT 2002


Hello 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

<snip>
JC> It's been suggested just to leave it as two queries, but I'd still be
JC> interested in seeing code to write it as one, even if I don't use it *this*
JC> time.
</snip>



--
Best regards,
 Michiel                            mailto:M.B.Trimpe at student.tue.nl





More information about the thelist mailing list