is this what you need?declare @sme table (UserID varchar(10), UserName varchar(40))insert @smeselect 'JXJohns', 'John Jones' union allselect 'BDJones', 'Brad Johnson' union allselect 'JPApple', 'Johny Appleseed'declare @SMEInvites table (UserID varchar(10) ,AppID int, Invited int)insert @SMEInvitesselect 'JXJohns', 12, 1 union allselect 'BDJones', 12, 1 union allselect 'BDJones', 15, 1
Queryselect COALESCE(b.Invited,0),a.UserNamefrom @sme a LEFT JOIN @SMEInvites b on a.UserID = b.UserID and b.AppID = 12
ResultInvited UserName----------- ----------------------------------------1 John Jones1 Brad Johnson0 Johny Appleseed