Sql 左连接与左连接右过滤数据集后过滤的等效性

Sql 左连接与左连接右过滤数据集后过滤的等效性,sql,Sql,这两条sql语句是否等效 select a.accountid, b.attribute1 from account as a left join dataset1 as b on a.accountid= b.accountid where b.attribute2= 'TEST'; 与之相反: select a.accountid, b.attribute1 from account as a left join (select * from dataset1 where attribut

这两条sql语句是否等效

select a.accountid, b.attribute1
from account as a
left join dataset1 as b
on a.accountid= b.accountid
where b.attribute2= 'TEST';
与之相反:

select a.accountid, b.attribute1
from account as a
left join (select * from dataset1 where attribute2= 'TEST') as b
on a.accountid= b.accountid;

查询可能会给出不同的结果

第一个查询将仅获取具有相应dataset1和dataset1的帐户。attribute2为“TEST”(因为您使用WHERE子句过滤整个结果集)


第二个查询将为您提供所有帐户,只是b.attribute1列只有在找到匹配的dataset1行时才是非空的

查询可能会给出不同的结果

第一个查询将仅获取具有相应dataset1和dataset1的帐户。attribute2为“TEST”(因为您使用WHERE子句过滤整个结果集)


第二个查询将为您提供所有帐户,只是b.attribute1列只有在找到匹配的dataset1行时才是非空的

查询会给出不同的结果,因为第一个查询实际上是一个
内部联接
——where子句会撤消外部联接

您要查找的语法是:

select a.accountid, b.attribute1
from account a left join
     dataset1 b
     on a.accountid = b.accountid and b.attribute2 = 'TEST';

查询会给出不同的结果,因为第一个查询实际上是一个
内部联接
——
where
子句会撤消外部联接

您要查找的语法是:

select a.accountid, b.attribute1
from account a left join
     dataset1 b
     on a.accountid = b.accountid and b.attribute2 = 'TEST';