【问题标题】:Issues with left join [duplicate]左连接问题[重复]
【发布时间】:2021-03-13 14:43:28
【问题描述】:

我想弄清楚我做错了什么

这是我的 JOIN

select * from table1 left outer join table2 on 
            table1.fkID = table2.fkID
            where table2.fkID= 500 order by 1 desc 

我应该多条记录,但我只得到 1 条,我在这里做错了吗

【问题讨论】:

标签: sql sql-server


【解决方案1】:

您需要将where 子句中的条件移动到on 子句中:

select *
from table1 left outer join
     table2
     on table1.fkID = table2.fkID and
        table2.fkID= 500
 order by 1 desc;

where 子句过滤掉 NULL 值,将外连接变为内连接。

【讨论】:

  • 它现在给了我这么多记录
猜你喜欢
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 2011-12-22
  • 2011-09-25
  • 2011-07-21
相关资源
最近更新 更多