hi...
i am new on left join. I don't really know the reason or concept of the problem that I found.
In following SQL, I want to retrieve all user group and tell me which group is assigned to a specific user. I have 2 user groups in "UserGroup" and 1 of the user group assigned to a user in "UserAssignedGroup".
First, I used this SQL. But it only return only 1 user group
select ug.UserSystem, ug.UserGroupCode, uag.UserCode
from UserGroup ug left join UserAssignedGroup uag on ug.UserGroupCode = uag.UserGroupCode
where uag.UserCode = 'test'
If I change to use sub-query then it return 2 user groups that I want.
select ug.UserSystem, ug.UserGroupCode, x.UserCode
from mp_UserGroup ug left join (select uag.UserSystem, uag.UserGroupCode, uag.UserCode from mp_UserAssignedGroup uag where uag.UserCode = 'test') x on x.UserGroupCode = ug.UserGroupCode
I am not sure the problem on the criteria of UserCode that limits the result set. Hope to see someone can share the knowledge with me.
Thank you