2016-07-11 67 views
1

嗨,我有以下實體:SQL連接4臺,並返回所有字段

USER

id_user Name Username role

TASK

id_task task_Name tipe

COMPLETED_TASK

id_task id_user

ASSIGNED_TASK

id_task id_user

有沒有什麼辦法讓任務的完整列表 「已完成並分配」 與一起相應的用戶?

我嘗試以下查詢,但因爲它未能返回所有TASK.id_task

SELECT * FROM TASK 
LEFT OUTER JOIN COMPLETED_TASK ON TASK.id_task=COMPLETED_TASK.id_task 
LEFT OUTER JOIN ASSIGNED_TASK ON TASK.id_task=ASSIGNED_TASK.id_task 
INNER JOIN USER ON USER.id_user=ASSIGNED_TASK.id_user 
OR USER.id_user=COMPLETED_TASK.id_user 
+0

顯示基於一些樣品輸入您的預計輸出這並不完全工作。 – 1000111

+0

使用此 SELECT * FROM TASK INNER JOIN COMPLETED_TASK ON TASK.id_task = COMPLETED_TASK.id_task INNER JOIN ASSIGNED_TASK ON TASK.id_task = ASSIGNED_TASK.id_task INNER JOIN使用者在USER.id_user = ASSIGNED_TASK.id_user OR USER.id_user = COMPLETED_TASK.id_user –

+0

我想這id_task,任務名稱,分配給用戶,任務TIPE但我真的需要id_task每一行 – Lollo

回答

0
the real problem, is that sql join or more exactly left join, 
return all the left table rows, 
but return null value for the fieldset, that not have match in ON clause. 

so i must fill a table whit all task,whit this head 
<thead><th>id_task</th><th>Nametask</th><th>Assigned to</th>th>Tipology</th> 

and i need for all task the fiedset id_task for edit and delete task. 
so seems evry type of join dont give this result whats that the impossiblequery