2017-05-09 68 views
0

我必須從像Userdetails,任務,timedetails三個表中獲取數據,所以我正在獲取數據,但它是基於timedetails表複製。例如person id是 - 1.它在timedetails表中呈現兩次,然後我得到重複的行。 我的查詢是避免重複在Mysql左加入查詢

SELECT GROUP_CONCAT(B.task_status) as task_status, 
     GROUP_CONCAT(B.task_type) as task_type, 
     GROUP_CONCAT(B.task_id) as task_id, 
     GROUP_CONCAT(B.task_name) as task_name, 
     A.us_id, 
     A.us_name, 
     C.out_time 
FROM ts_userdetails A 
LEFT JOIN 
     cms_task B 
ON  B.emp_id = A.us_id 
LEFT JOIN 
     ts_timedetails C 
ON  C.user_id=A.us_id 
WHERE C.entry_date='2017-05-09' AND 
     A.us_id!='1' 
GROUP BY C.user_id 

我越來越像結果 enter image description here

我不想顯示的字段重複的事情。

如果我對某個特定人員有2個timedetails意味着發生了2次重複。我只想要一次。

+0

請添加您的輸入,您的結果和你想要和格式化文本。沒有放大鏡,該圖像幾乎不可讀... –

+0

這似乎是一個非常有用的結果。只是說。 – Strawberry

+0

我們正在使用此結果報告目的 –

回答

0

使用distinct關鍵字

SELECT GROUP_CONCAT(distinct B.task_status) as task_status,GROUP_CONCAT(distinct B.task_type) as task_type,GROUP_CONCAT(distinct B.task_id) as task_id,GROUP_CONCAT(distinct B.task_name) as task_name,A.us_id,A.us_name,C.out_time FROM ts_userdetails A LEFT JOIN cms_task B ON B.emp_id = A.us_id LEFT JOIN ts_timedetails C ON C.user_id=A.us_id WHERE C.entry_date='2017-05-09' AND A.us_id!='1' GROUP BY C.user_id 
+0

如果我把分組前co​​ncat然後狀態我不會得到所有任務。狀態是固定的0,1,2 –

+0

如果你看看查詢,你會注意到''distinct'被放在'group_concat'裏面,這意味着它只會影響它的內容...... – Alexey

+0

啊,我想我能讓你......好,那是不可能的。你在group_concat中有不同的值或者獲取所有重複值。 – Alexey