I am using SQL Server 2008.
I have two tables
User ( UserID, Name, Link )UserNotes ( NoteID, UserID, Title, Description )
This is the sample data structure.
INSERT INTO [User] ([UserID], [Name], [Link]) VALUES (1, 'John', 'L1'), (2, 'Steve', 'L234'); INSERT INTO [UserNotes] ([NoteID], [UserID], [Title], [Description]) VALUES (1, 1, 'AboutJohn', 'This is about john'), (2, 1, 'John Work', 'This is where John work'), (3, 1, 'John Education', 'This is the uni where John go'), (4, 2, 'Steve Note1', 'Des1 about Steve'), (5, 2, 'Steve Note2', 'Des2 about Steve');
Here is the SQL Fiddle
I want to create a view ( User_view ) as follows, and when I execute this command, the output should be as follows.
SELECT * FROM User_view WHERE UserID IN (1) UserID Name AboutJOhn JohnWork JohnEducation 1 John This is about john This is where Johnwork This is the uni where John go
Title column of the child table should become the name of the column, and Description should become the value of this column, and we do not know how many rows we will have. I know about this problem when we select two users and which name uses the column name. In this case, we can use (Note1, Note2, Note3, etc. For multiple users), otherwise use the header field as the column name. Can this be done? Hooray!