我是新的Sql Queries。我想根据两个表的不同来制作一个表 这是我的疑问:
SELECT * FROM `question` WHERE `relatedFields` = 'Math' LEFT JOIN `answer` ON `question`.ques = `answer`.ques where `answer`.TeacherNumber=1111111111
请帮忙。
答案 0 :(得分:2)
将第一个WHERE
子句移到最后,并将其他条件移到ON
以使其成为真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
答案 1 :(得分:1)