I have 2 table which storing Students data
Table A
Name | id | Course |
---|---|---|
Bob | 1 | Marketing |
Dom | 2 | Science |
Edward | 3 | IT |
Table B
Name | id | Course |
---|---|---|
Dom | 2 | Mathematic |
Chris | 4 | IT |
Now I plan to display all student data as below
Name | id | Course |
---|---|---|
Bob | 1 | Marketing |
Dom | 2 | Science, Mathematic |
Edward | 3 | IT |
Chris | 4 | IT |
SELECT
CASE WHEN a.name = b.name THEN a.name ELSE a.name as Student_Name,
CASE WHEN a.id = b.id THEN a.id ELSE a.id as Student_Id,
CASE WHEN a.course = b.course THEN a.course + ',' + b.course ELSE a.course as Student_Course
FROM student a
full join student b on a.name=b.name
But with above query I only able to get the result as
Name | id | Course |
---|---|---|
Bob | 1 | Marketing |
Dom | 2 | Science, Mathematic |
Edward | 3 | IT |
NULL | NULL | NULL |
Which Chris become NULL in final result...How can I make it to select all? Have suffer on this whole week.