I am trying to work with an Olympic database where I am tasked with modifying the information I know about Olympians who have tied in the same event.
“Firstly, extend the query to show more details about the event: in
place of the event id, display the event-gender, distance and style.
As part of this, the output is now to be sorted by event-gender,
distance, style. and then place.Secondly, show more details about each of the two competitors: in
place of each competitor number, display their given and family names
and the name of their country (not the country code).”
The four tables that I have to work with are:
Competitors, which contains: CompetitornNum, Givenname, Familyname.
Results, which contains: Eventid, CompetitorNum, Place.
Events, which contains: Eventid, Eventgender, Distance, Style
Countries, which contains: Countryname
Is my original query.
SELECT C1.EventID, C1.Place, C1.CompetitorNum, C2.CompetitorNum
FROM Results C1, Results C2
WHERE C1.Place = C2.Place
and C1.EventID = C2.EventId
and C1.CompetitorNum < C2.CompetitorNum
ORDER BY C1.EventID;
My problem is that I have a notion as to what I need to do, but the program we have been told to use crashes every time I try something out, I really dont know where to go from here.
SELECT Eventgender, Distance, Style, C1.Place, Givenname, Familyname, Countryname, Givenname, Familyname, Countryname
FROM Results C1, Results C2
natural join Competitors
natural join Countries
natural join Events
WHERE C1.Place = C2.Place
and C1.EventId = C2.EventId
and C1.CompetitorNum < C2.CompetitorNum
ORDER BY C1.EventID;
I am looking to select the Givenname, Familyname and Countryname of person 1, and person 2 instead of the CompetitorNum I am currently retrieving.
My new query finds the first person, but I am not sure how to change to obtain the seconds persons information.
Any help would be greatly appreciated
I seem to have found a solution, however I am not sure if I am using the best method to accomplish the task. Is there a better way to do it?
SELECT C5.Eventgender, C5.Distance, C5.Style, C1.Place, C3.Givenname,
C3.Familyname, C6.Countryname, C4.Givenname, C4.Familyname, C7.Countryname
FROM Results C1
join Results C2 on C1.Place = C2.Place and C1.EventId = C2.Eventid
and C1.Competitornum < C2.Competitornum
join Competitors C3 on C3.Competitornum = C1.Competitornum
join Competitors C4 on C4.Competitornum = C2.Competitornum
join Events C5 on C5.Eventid = C1.Eventid
join Countries C6 on C6.Countrycode = C3.Countrycode
join Countries C7 on C7.Countrycode = C4.Countrycode
ORDER BY C1.EventId;
1 Answer