I have two tables connected with many-to-many relation by junction table:
CREATE TABLE [dbo].[User](
[ID] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) NOT NULL,
[surname] [nvarchar](50) NOT NULL,
)
CREATE TABLE [dbo].[Room](
[ID] [int] IDENTITY(1,1) NOT NULL,
[number] [nvarchar](50) NOT NULL
)
CREATE TABLE [dbo].[Permission](
[ID] [int] IDENTITY(1,1) NOT NULL,
[user_id] [int] NOT NULL,
[room_id] [int] NOT NULL
)
I want to build an query that would give me in result name and surename from User table and list of rooms that given user have permission. For example:
name surname rooms
Jon Doe [134,143,132]
I managed to get a few results for Jon Doe each for one room but I'm not able to collapse this to get on record for each user.