0
SELECT * FROM Training_Registration registration
LEFT OUTER JOIN Training_Segment segment
    ON registration.referenceId = segment.id
LEFT OUTER JOIN Training_Module module
    ON segment.moduleId = module.id
    OR registration.referenceId = module.id 
INNER JOIN Training_Course course
    ON module.courseId = course.id 
    OR registration.referenceId = course.id 
WHERE registration.traineeId = @traineeId
AND registration.registrationDate >= @startDate
AND course.courseTemplateId = @courseTemplateId
;

for this 4 table relationship. 
Registration FK > Segment , Module , Course
Segment FK > Module
Module FK > Course
Course FK > CourseTemplate

I already get what the result I want, but I can't explain what happen here. I change the left out or left also can get the result. The last join is left or right or whatever also can get the result.

Can someone help me explain this MySQL Script.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
  • `LEFT JOIN` and `LEFT OUTER JOIN` are basically synonymous in MySQL. Is that what your question is about? – Tim Biegeleisen Jul 27 '18 at 10:55
  • In order to get an answer you need to explain what you want to do and a clear question. – hugoShaka Jul 27 '18 at 11:13
  • Maybe [this old SO post](https://stackoverflow.com/questions/448023/what-is-the-difference-between-left-right-outer-and-inner-joins) could bring some enlightment about join types. – LukStorms Jul 27 '18 at 18:33
  • After having a closer look at the SQL. This one is a bit special. Because more often one links 1 table to another table, then that 1 to another... etc. But in this SQL those OR's are used to also link the base registration table to all the others. – LukStorms Jul 27 '18 at 18:45

0 Answers0