Hi
I'm new to SQL. I'm trying to pull data from a main table and include descriptive columns from two other tables. I can't seem to get the joins right because no matter how I try I only get 26761 rows returned, when I know that when I pull the data from the single main table without any joins there are 53, 262 rows.
Here's the current query.
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 Class_Details.ClassId = StudentBookingDetails.ClassId LEFT OUTER JOIN
Locations ON Class_Details.LocationId = Locations.ID
WHERE (StudentBookingDetails.ClassStartDate >= CONVERT(DATETIME, '2014-01-01 00:00:00', 102))
- StudentBookingDetails is an SQL View with details about students booked in to various classes. This is the main table, which returns 53,262 rows without any joins, but I need to include descriptive columns from two other tables:
- Class_Details - has info about the actual classes (description etc.) plus a common column with the Locations table
- Locations table has descriptive columns about the locations the classes are provided in.
I need to get all the student info for 2014 and include a couple of columns from Class_Details and from Locations. There is no common column between StudentBookingDetails and Locations.
Can someone please help? I'm sure I'm just making a basic newbie mistake.
Mark
No comments:
Post a Comment