0

i have to take data from three tables like Userdetails,tasks,timedetails so i am getting data but it is duplicating based on the timedetails table. for example person id is - 1. it is presented two times in timedetails table then i'm getting duplicate rows. my query is

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

I am getting results like enter image description here

I don't want duplicated things in displayed fields.

If I have 2 timedetails for one particular person id means 2 times duplication occurs. I just want one time.

3
  • Please add your input, your result and the result you'd want as well formatted text. That image is barely readable without a magnifier... Commented May 9, 2017 at 8:16
  • It seems like a really un-useful result. Just saying. Commented May 9, 2017 at 8:38
  • we are using this result for report purpose Commented May 9, 2017 at 9:13

1 Answer 1

1

use distinct keyword

    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
Sign up to request clarification or add additional context in comments.

3 Comments

if i put distinct before group concat then status i will not get for all tasks. status are fixed 0,1,2
If you look into the query you will notice that distinct is placed inside group_concat meaning it will affect only it's contents...
Ah, I think I get you...well, that's not possible. you either have distinct values in group_concat or get all the duplicates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.