【问题标题】:inner join two tables having null values on the foreign keys of each other内连接两个在彼此的外键上具有空值的表
【发布时间】:2018-12-19 16:54:26
【问题描述】:

我在table1的数据库中有以下数据

我运行以下查询并没有返回任何内容

SELECT
  someColumns

  FROM table1

  INNER JOIN table2 ON table1.id = table2.id
  INNER JOIN table3 ON table1.anotherId = table3.anotherId 

我想返回 (table2 with id = table1.id and table3 with anotherId = table1.anotherId) 中的所有记录

【问题讨论】:

  • 你应该阅读一下 INNER 和 OUTER 连接之间的区别

标签: mysql sql null foreign-keys inner-join


【解决方案1】:

您应该使用LEFT OUTER JOIN 来获得指定的结果。

【讨论】:

    猜你喜欢
    • 2015-06-19
    • 2020-11-26
    • 2014-07-17
    • 2021-03-08
    • 2015-02-13
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多