【问题标题】:how to use outer-join with a where clause in an empty Table如何在空表中使用带有 where 子句的外连接
【发布时间】:2013-09-05 13:39:27
【问题描述】:

您好,我需要知道如何从查询(通过外部联接连接 2 个表)中获取结果,即使指向空表的 where 子句没有结果。

例子:

结果当前的样子SQLFiddle
结果应该看起来像SQLFiddle

【问题讨论】:

    标签: sql where-clause outer-join


    【解决方案1】:

    在本例中使用外连接时,不要使用 WHERE 子句,因为它会将其视为内连接。

    所以只说 AND 而不是 where

    SELECT *
    FROM FilledTable 
    LEFT OUTER JOIN EmptyTable 
    ON FilledTable.Id = EmptyTable.RefFilledTableId
    and EmptyTable.Value = 5
    

    http://sqlfiddle.com/#!2/7a96a/9

    【讨论】:

    • Turst me 前一阵子我和你在同一条船上,直到有人指出,外连接通常不应该使用 Where 子句,因为那里被视为内连接......我很惊讶呵呵
    猜你喜欢
    • 2013-08-25
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    相关资源
    最近更新 更多