34,590
社区成员
发帖
与我相关
我的任务
分享
此查询使用的不是 ANSI 外部联接运算符("*=" 或 "=*")。若要不进行修改即运行此查询,请使用存储过程 sp_dbcmptlevel 将当前数据库的兼容级别设置为 80 或更低。极力建议使用 ANSI 外部联接运算符(LEFT OUTER JOIN、RIGHT OUTER JOIN)重写此查询。在将来的 SQL Server 版本中,即使在向后兼容模式下,也不支持非 ANSI 联接运算符。
select * from
table1 a,table2 b ,table3 c
where a.id *= b.id
and a.id *= c.id
declare @t1 table (id int, value int)
insert @t1 select 1,1 union all
select 2,2 union all
select 3,2
declare @t2 table (id int, value int)
insert @t2 select 1,1
select * from @t1 a ,@t2 b where a.id*=b.id
(3 行受影响)
(1 行受影响)
id value id value
----------- ----------- ----------- -----------
1 1 1 1
2 2 NULL NULL
3 2 NULL NULL
(3 行受影响)
select * from table1, table2,table3 where table1.id = table2.id and table1.id = table3.id
--上面的写法和下面的写法应该是一个意思,即说明上面的写法跟inner join是一样的
select * from table1 inner join table2 on table1.id = table2.id
inner join table1.id = table3.id
而我想知道,就用上面的写法,不用这些join的关键字,怎样写出left join来???????declare @t1 table (id int, value int)
insert @t1 select 1,1 union all
select 2,2 union all
select 3,2
declare @t2 table (id int, value int)
insert @t2 select 1,1
select * from @t1 a left join @t2 b on a.id=b.id
(3 行受影响)
(1 行受影响)
id value id value
----------- ----------- ----------- -----------
1 1 1 1
2 2 NULL NULL
3 2 NULL NULL
(3 行受影响)
select * from table1,table2,table3 where .. .. . . .. --这样行吗,实现left join
SELECT *
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
LEFT JOIN table3
ON table1.id = table3.id
?Left Outer Join 运算符返回满足第一个(顶端)输入与第二个(底端)输入联接的每一行。它还返回任何在第二个输入中没有匹配行的第一个输入中的行。第二个输入中的非匹配行作为空值返回。如果 Argument 列内不存在任何联接谓词,则每行都是一个匹配行。