MySQL Forums
Forum List  »  Newbie

Re: Need help withquery
Posted by: Peter Brawley
Date: October 18, 2016 09:30PM

Explicit join syntax (From ... Join ... On ...) makes query design, query debugging and query maintenance much clearer and easier for everybody ...

SELECT 
  p.Preferred_Name, p.Last_Name, 
  g.Guest_First_Name, g.Guest_Last_Name, 
  e.Event_Description 
FROM person   p
JOIN guest    g ON p.Person_ID = g.Person_ID 
JOIN attendee a ON g.Person_ID = a.Person_ID 
JOIN `event`  e ON a.Event_ID = e.Event_ID  
WHERE a.Guest_Attended = 'Y' AND a.Event_ID = 4 
ORDER BY p.Last_Name, p.First_Name, g.Guest_Last_Name, g.Guest_First_Name ;

I removed DISTINCT because its purpose is unclear. The query says to find persons, who link to guests, who link to attendees, who link to eventID=4. Is that what's intended? If it isn't, what is? If it is, then you may need to post a few Inserts for these tables so we can understand what's wrong with the results you're seeing.



Edited 2 time(s). Last edit at 10/19/2016 09:16AM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
October 18, 2016 05:22PM
Re: Need help withquery
October 18, 2016 09:30PM
October 19, 2016 10:18AM
October 19, 2016 10:27AM
October 19, 2016 11:04AM
October 19, 2016 03:16PM
October 20, 2016 11:11AM
October 20, 2016 02:01PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.