I have two tables Lecturer
and Student
and I would like to display the other lecturer id's in the new column with comma separated values. I am using SQL Server 2014.
Table: Lecturer
id name subject
-------------------------------
102 Mark Designing
103 John Analytics
104 Jacob Science
Table: StudentLecturer
id Fname Lname Lid
--------------------------------
1 Jack P 102
1 Jack P 103
1 Jack P 104
By using group by I am getting a single value as below:
SELECT id, fname, lname, lid
FROM studentlecturer
GROUP BY id
Table: StudentLecturer
id Fname Lname Lid
--------------------------------
1 Jack P 102
Expected result
id Fname Lname Lid Concat Values
---------------------------------------------------
1 Jack P 102 103,104
1 Jack P 103 102,104
1 Jack P 104 102,103
SQL Fiddle: http://sqlfiddle.com/#!7/73304