Looking to get ALL UserName
from UsersDataTbl
and matching UserName
from EnrollmentsTbl
if it exist. but I want to identify w
You can us the is not null
to test if a field's value is null or not and return a true or false. If the username does not exist in EnrollmentsTbl
then the left join will return null
in its place.
I moved the e.ClassName LIKE 'Word%
criterion from the where
clause to the join condition, since it changed the left join
into an inner join
defeating the whole purpose of the query.
SELECT u.UserName
, (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.UserName LIKE 'bar%'