Can someone please readthrough this code

October 19, 2010 at 04:06:09
Specs: Windows Vista
Independently the queries work fine, and produce the result I want them to. But when I bring them together it doesnt produce the same result anymore.. I get two colums instead of three, and lots of repeats!

SELECT ATHLETE.Athlete_lname, Count(MEDAL.Cont_id) AS [# of medal]
FROM ATHLETE, REPRESENTATIVE, CONTESTANT, MEDAL
WHERE ATHLETE.Athlete_id=REPRESENTATIVE.Athlete_id and REPRESENTATIVE.Rep_id=CONTESTANT.Rep_id and CONTESTANT.Cont_id=MEDAL.Cont_id
GROUP BY ATHLETE.Athlete_lname

UNION SELECT Athlete_lname, COUNT(GAME.Game_id) AS GAMES
FROM ATHLETE, REPRESENTATIVE, GAME
WHERE ATHLETE.Athlete_id=REPRESENTATIVE.Athlete_id AND REPRESENTATIVE.Game_id=GAME.Game_id
GROUP BY Athlete_lname;


??


Thanks Thor :)


See More: Can someone please readthrough this code

Report •


#1
December 16, 2010 at 15:30:31
Do you really get three columns when running those queries independently? Could it be possible to have a print of your desired output? And, about the repetitions, your are doing two individual counts and then unifying the results, so the first query can give you a "DAVID,25" and the second "DAVID,30" the union will contain both results.

Report •
Related Solutions


Ask Question