문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top