我正在尝试运行一个查询,该查询使用 WHERE 子句从表中选择值,该查询仅返回所有条件都有值的行,我是否要返回同样为空的值?

     Language Table                            Students Table
 ID    Language                        ID      Student      LanguageID
  1     English                         1        Joe
  2     Spanish                         2        Mike          1

运行查询,例如
Select student.ID , Student.Student , Language.language
FROM
    Students, Language
WHERE
    student.LanguageID = Language.id

该查询仅返回学生迈克的单行,即使语言设置为空,我也想返回所有学生。

最佳答案

你想要这样的东西:

select
  student.id, student.student, language.language
from
  student left join language
      on student.languageid = language.languageid

关于where-clause - Sql在WHERE子句中选择空值和非空值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3127541/

10-13 08:10