gpt4 book ai didi

MySql 查询 : Left Join

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

我是新的 Sql 查询。我想从两个表的差异中创建一个表。
这是我的查询:

SELECT * FROM `question` WHERE `relatedFields` = 'Math' LEFT JOIN  `answer` ON `question`.ques = `answer`.ques where `answer`.TeacherNumber=1111111111

请帮忙。

最佳答案

将第一个 WHERE 子句移动到末尾,并将另一个 where 条件移动到 ON 以获得 true LEFT JOIN:

SELECT *
FROM `question`
LEFT JOIN `answer` ON `question`.ques = `answer`.ques
and `answer`.TeacherNumber=1111111111
where `question`.relatedFields = 'Math'

替代语法:

SELECT *
FROM
(select * from `question` WHERE `relatedFields` = 'Math') as q
LEFT JOIN
(select * from `answer` where TeacherNumber = 1111111111) as a
ON q.ques = a.ques

关于MySql 查询 : Left Join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32564140/

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