0

I am trying to select data from 3 separate tables, where 2 of those contains multiple rows of data. The sql query i am using is this, but i am experiencing that when i run it, if either taskdependees or tasksdependencies have zero result, the whole task is not showing.

SELECT t.*, GROUP_CONCAT(a.DependenciesId) as DiesId, GROUP_CONCAT(b.DependeesId) as DeesId FROM tasks t JOIN tasksdependencies a ON a.TasksId=t.TasksId JOIN taskdependees b ON b.TasksId=t.TasksId GROUP BY t.TasksId

What am I doing wrong in this query?

1
  • try a left join instead of a join Commented May 8, 2014 at 15:53

1 Answer 1

2

Use LEFT JOIN , inner join will give row if there is association is present in both tables while left will return the rows from left table even if they are not associated

SELECT t.*, GROUP_CONCAT(a.DependenciesId) as DiesId,
 GROUP_CONCAT(b.DependeesId) as DeesId 
FROM tasks t
LEFT JOIN tasksdependencies a ON a.TasksId=t.TasksId
LEFT JOIN taskdependees b ON b.TasksId=t.TasksId 
GROUP BY t.TasksId
Sign up to request clarification or add additional context in comments.

1 Comment

very usefull! i was posting a question like this and I found the answer, really thank you :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.