Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a user table and each user may have many roles and each role have many permission how i get all record in one query?
out put like this

i need complete user information how many roles they have and how many permission they have.

What I have tried:

select user.username,user.officeID from user join
userRole on user.UserID=UserRole.UserID join
Role on UserRole.RoleID=Role.ID join RolePermission on Role.ID=RolePermission.RoleID join Permission on RolePermission.ID=PermissionID
Posted
Updated 28-Jul-16 15:12pm
v2

1 solution

Its unclear what sort of output you are expecting but I think you need to investigate the different join types

See T-SQL Join Types | T-SQL content from SQL Server Pro

Also you get to be clear on your script where field name are common that the correct table field name is used.

eg

SQL
Select a.id, b.UID, x,y from table1 a left join table2 b on a.id = b.id left join table3 c on b.UID = c.IUD
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900