gpt4 book ai didi

mysql - sql连接4个表并返回所有字段

转载 作者:行者123 更新时间:2023-11-30 22:15:54 25 4
gpt4 key购买 nike

您好,我有以下实体:

用户:

id_user
姓名
用户名
作用

任务:

id_task
任务名称
提示

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

最佳答案

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

关于mysql - sql连接4个表并返回所有字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38299140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com