I have three tables.
tblLink: (LinkId, LinkName, GroupId, ,SubGroupId)
GroupId and SubGroupId are foreign key in tblGroup and tblSubGroup
tblGroup: (GroupId, GroupName)
tblSubGroup: (SubGroupId, SubGroupName)
in tblLink SubGroupId is allowed Null but GroupId is Mandatory.
I want to fetch LinkName, GroupName, SubGroupName for every LinkId in tblLink
I have written a query
SELECT L.LinkName, G.GroupName, SG.SubGroupName FROM tblLink L
Left Join
tblSubGroup SG
ON
(L.SubGroupId=SG.SubGroupId)
Inner Join
tblGroup G
ON
(L.GroupId=G.GroupId)
If there is no subgroup for some LinkId I want to show NotExist instead of Null