Reputation: 21
How to join two tables that have a common field in third table?
E.g: Table A has RoleId, role description and Table B has AccessId,Access description.Table C has RoleAccessID,roleid, accessid. I need to display role description and their access description.Please let me know how to achieve this.
Upvotes: 1
Views: 41
Reputation: 153
try this
SELECT
role.RoleID,
role.Role_Description,
ac.AccessId,
ac.Access_Description
FROM tblRole role
INNER JOIN tblRoleAccessInfo rac ON A.RoleId = C.RoleId
INNER JOIN tblAccessInfo ac ON C.AccessId = B.AccessId
Upvotes: 1
Reputation: 16908
You can Try this below logic for your purpose-
SELECT A.role_description, B.access_description
FROM TABLE_A A
INNER JOIN TABLE_C C ON A.RoleId = C.RoleId
INNER JOIN TABLE_B B ON C.AccessId = B.AccessId
Upvotes: 1