似乎select * from table1, table2,table3 where table1.id = table2.id and table1.id = table3.id和
select * from table1 inner join table2 on table1.id = table2.id
inner join table1.id = table3.id
是等价的。
我想问,怎样能在前者的情况下实现left join呢
select * from table1 inner join table2 on table1.id = table2.id
inner join table1.id = table3.id
是等价的。
我想问,怎样能在前者的情况下实现left join呢
SELECT *
FROM table1
LEFT JOIN table2
ON table1.id = table2.id
LEFT JOIN table3
ON table1.id = table3.id?
如果没有left join,就用第一种那样的形式可以吗?select * from table1,table2,table3 where .. .. . . .. --这样行吗,实现left join
insert @t1 select 1,1 union all
select 2,2 union all
select 3,2declare @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 行受影响)
--上面的写法和下面的写法应该是一个意思,即说明上面的写法跟inner join是一样的
select * from table1 inner join table2 on table1.id = table2.id
inner join table1.id = table3.id而我想知道,就用上面的写法,不用这些join的关键字,怎样写出left join来???????
insert @t1 select 1,1 union all
select 2,2 union all
select 3,2declare @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 行受影响)
table1 a,table2 b ,table3 c
where a.id *= b.id
and a.id *= c.id
我明白了,重点是那个 "*=", "*="标识left join ,"=*"标识right join对吧!!可是执行报了个错!此查询使用的不是 ANSI 外部联接运算符("*=" 或 "=*")。若要不进行修改即运行此查询,请使用存储过程 sp_dbcmptlevel 将当前数据库的兼容级别设置为 80 或更低。极力建议使用 ANSI 外部联接运算符(LEFT OUTER JOIN、RIGHT OUTER JOIN)重写此查询。在将来的 SQL Server 版本中,即使在向后兼容模式下,也不支持非 ANSI 联接运算符。这是不是说明这种写法已经过时了???