我必须从三个表中获取数据,例如Userdetails,tasks,timedetails,所以我获取数据,但它是基于timedetails表重复的。例如,人物ID是 - 1.它在timedetails表中呈现两次,然后我得到重复的行。 我的查询是
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
我不希望在显示的字段中出现重复的内容。
如果我有一个特定人的2个时间序列,则表示重复发生2次。我只想要一次。
答案 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