日期:2014-05-18 浏览次数:20972 次
select b.kid, a.type from a, b where b.kid*=a.id --带* select b.kid, a.type from a, b where b.kid=a.id --不带* select tb1.* from tb1 left outer join tb2 on tb1.col1=tb2.col1 --join
{第一种*的存在不知道是为了什么。}
{曾听说 第二种方法有时不能正确显示,其中原因不明。}
{第三种是常用的join,一般都这么进行做外关联查询。}
if object_id('[a]') is not null drop table [a]
create table [a] (id int,type varchar(1))
insert into [a]
select 1,'a' union all
select 2,'b' union all
select 3,'c'
if object_id('[b]') is not null drop table [b]
create table [b] (kid int,col varchar(2))
insert into [b]
select 2,'bh' union all
select 3,'bn' union all
select 4,'bm'
select b.kid, a.type from a, b where b.kid*=a.id --带*
/*
The query uses non-ANSI outer join operators ("*=" or "=*").
*/
select b.kid, a.type from a, b where b.kid=a.id --不带*
/*
kid type
----------- ----
2 b
3 c
*/
select a.*,b.* from a left outer join b on b.kid=a.id --join
/*
id type kid col
----------- ---- ----------- ----
1 a NULL NULL
2 b 2 bh
3 c 3 bn
*/
------解决方案--------------------
1.第一种情况SQL SERVER 2005开始被取消。
2.第二种是内连接,第三种是左连接,结果不一样的。
------解决方案--------------------
第一种是老写发,2005 之后已经不支持
第二个是内链接
第三个是外连接