I'm joining multiple tables in which I want one column value into row according to TechnicianName:
I have 4 tables
easy_tbljobcard,easy_tbltechnicianandeasy_tblproblemandeasy_tbltechnicianMasterI am getting
TechnicianNamein 2nd column fromeasy_tbltechnicianMasterwheretechnicianIdexist ineasy_tbltechnicianI want
STUFFin 3rd column in my query (p.ProblemReported)
Current SQL statement:
SELECT j.CardID,
, (SELECT TechnicianName FROM easy_tbltechnicianMaster WHERE TechnicianID = t.technicianID) AS TechnicianName
, p.ProblemReported
FROM easy_tbljobcard AS j
JOIN easy_technician AS t ON t.CardID = j.CardID
LEFT JOIN easy_tblproblem AS p ON p.CardID = t.CardID
Query result:
╔══════════╦══════════════════╦═══════════════════╗
║ CardID ║ TechnicianName ║ ProblemReported ║
╠══════════╬══════════════════╬═══════════════════╣
║ 1 ║ AKBAR ║ PROBLEM A ║
║ 1 ║ AKBAR ║ PROBLEM B ║
║ 1 ║ AKBAR ║ PROBLEM C ║
║ 1 ║ ASANKA ║ PROBLEM A ║
║ 1 ║ ASANKA ║ PROBLEM B ║
║ 1 ║ ASANKA ║ PROBLEM C ║
╚══════════╩══════════════════╩═══════════════════╝
The result above should be converted into this :
╔══════════╦══════════════════╦═════════════════════════════════╗
║ CardID ║ TechnicianName ║ ProblemReported ║
╠══════════╬══════════════════╬═════════════════════════════════╣
║ 1 ║ AKBAR ║ PROBLEM A, PROBLEM B, PROBLEM C ║
║ 1 ║ ASANKA ║ PROBLEM A, PROBLEM B, PROBLEM C ║
╚══════════╩══════════════════╩═════════════════════════════════╝
How to do this while joining multiple tables ?