【问题标题】:sql join 4 table and return all fieldssql加入4个表并返回所有字段
【发布时间】:2016-11-12 22:33:42
【问题描述】:

您好,我有以下实体:

TABLEUSER

id_user Name Username role

TABLETASK

id_task task_Name tipe

COMPLETED_TASK

id_task id_user

TABLEASSIGNED_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 

【问题讨论】:

  • 根据一些示例输入显示您的预期输出。
  • 使用此 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 ON USER.id_user=ASSIGNED_TASK.id_user OR USER。 id_user=COMPLETED_TASK.id_user
  • 我想要这个 id_task ,任务名称,分配给用户,任务提示,但我真的需要 id_task 在每一行
  • Rakesh Kumar 这我得到 0 行没有结果集很容易理解为什么
  • 您介意我为了清楚起见修改您的问题吗? @Lollo

标签: mysql sql join left-join


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 2012-04-13
    • 1970-01-01
    • 2018-08-07
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多