1
SELECT
A.id AS id,
Group_Concat(B.value) AS values,
Group_Concat(C.ac_id) AS ac_id,
Concat(D.first_name,' ',D.last_name) AS updatedBy
FROM A
LEFT JOIN B
ON A.id = B.id
LEFT JOIN C
ON A.id = C.id
LEFT JOIN D
ON A.modified_by = D.user_id
WHERE
A.status!='deleted'
AND A.created_by = '18'
GROUP BY A.id;
表B & C具有多行corressponding到A.id這就是爲什麼我使用這些領域GROUP_CONCAT但我得到錯誤的結果對於那些已分組columns.query返回結果一樣查詢返回錯誤的結果
+---------+-------------------------+-------------------------+-------------+
| id | values | ac_id | updatedBy |
+---------+-------------------------+-------------------------+-------------+
| 8 | A,A,A,B,B,B,C,C,C,D,D,D | 1,5,6,1,5,6,1,5,6,1,5,6 | Abdul |
+---------+-------------------------+-------------------------+-------------+
,但我需要你的GROUP_CONCAT()
這樣
+---------+-------------------------+-------------------------+-------------+
| id | values | ac_id | updatedBy |
+---------+-------------------------+-------------------------+-------------+
| 8 | A,B,C,D | 1,5,6 | Abdul |
+---------+-------------------------+-------------------------+-------------+