Domanda

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?

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top