Monday, November 3, 2014

Join three tables not getting all the data from the main table

Hi,


Have you tried putting StudentBookingDetails.ClassId on the left side?



SELECT StudentBookingDetails.ClassId, StudentBookingDetails.ClassType, StudentBookingDetails.ClassStartDate, Class_Details.LessonLevel, Class_Details.LocationId, Locations.LocationName, Locations.Description,
StudentBookingDetails.StudentId, StudentBookingDetails.StudentName
FROM StudentBookingDetails LEFT OUTER JOIN
Class_Details ON StudentBookingDetails.ClassId = Class_Details.ClassId LEFT OUTER JOIN
Locations ON Class_Details.LocationId = Locations.ID
WHERE (StudentBookingDetails.ClassStartDate >= CONVERT(DATETIME, '2014-01-01 00:00:00', 102))

This should give all rows from StudentBookingDetails regardsless whether it has a match in Class_Details.


Hope this helps.

~ J.




No comments:

Post a Comment