gpt4 book ai didi

MySQL 连接返回 Null

转载 作者:行者123 更新时间:2023-11-29 01:11:40 24 4
gpt4 key购买 nike

我有两张 table

Table_1
id|subject_code|subject_id
1|Test1 |1
2|Test2 |2
3|Test3 |3

Table2
id|subject_id|grade|status
1|1 |5.00 |Fail
2|3 |2.25 |Pass

现在,我想创建一个将返回以下内容的查询,

Table3
subject_code|grade|status
Test1 |5.00 |Fail
Test2 |NULL |NULL
Test3 |2.25 |Pass

我读过有关组合左连接和联合的信息,但我不知道如何做到这一点。提前致谢。

最佳答案

尝试左连接,像这样::

Select 
DISTINCT(table1.subject_code),
grade,
status

from table1
LEFT join table2 on (table1.subject_id=table2.subject_id)

关于MySQL 连接返回 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13699453/

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