34,873
社区成员
发帖
与我相关
我的任务
分享
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
*/