looking to join another table onto existing working example:
Working SQL:
SELECT u.UserName, u.LastName
, (e.UserName IS NOT NULL) as user_exists_in_EnrollmentsTbl
FROM UsersDataTbl u
LEFT
JOIN EnrollmentsTbl e
ON u.UserName = e.UserName
AND e.ClassName LIKE 'Word%'
WHERE u.Career = 1 AND Active = 1 ORDER BY u.LastName
My Attempt:
(SELECT u.UserName, u.LastName, d.Station
, (e.UserName IS NOT NULL) as completedl
FROM UsersDataTbl u
LEFT
JOIN EnrollmentsTbl e
ON u.UserName = e.UserName
AND e.ClassName LIKE 'Word%')
INNER JOIN UsersDataCareerTbl d
ON u.UserName = d.UserName
WHERE u.Career = 1 AND Active = 1 ORDER BY u.LastName
Solved
figured it out:
SELECT u.UserName, u.LastName, d.Station, (e.UserName IS NOT NULL) as completed
FROM (UsersDataTbl u
INNER JOIN UsersDataCareerTbl d ON u.UserName = d.UserName)
LEFT
JOIN EnrollmentsTbl e
ON u.UserName = e.UserName
AND e.ClassName LIKE 'Word%'
WHERE u.Career = 1 AND Active = 1 ORDER BY u.LastName
No comments:
Post a Comment