这是我给你测试,写了2个查询语句,其结果的在有些情况下是一样的,有些情况下是不同的
程序代码:
create table person(id int,name char(10),compid int,addrid int,codeid int)
create table comp (id int, compname char(20))
create table addr (id int, addrname char(20))
create table code (id int, codename char(20))
go
insert into person values(1,'a',1,1,1)
insert into person values(2,'b',1,1,1)
insert into person values(3,'c',1,1,2)
insert into person values(4,'d',2,2,2)
insert into comp values(1,'acomp')
insert into comp values(2,'bcomp')
insert into addr values(1,'addra')
insert into addr values(2,'bddra')
insert into code values(1,'acode')
--insert into code values(2,'bcode') --如果执行这一行,两个查询结果就一样,否则就不同
go
select a.id,a.name,,c.addrname,d.codename from ((person as a inner join comp as b on )
inner join addr as c on a.addrid=c.id) inner join code as d on a.codeid=d.id
select a.id,a.name,,c.addrname,d.codename from ((person as a left outer join comp as b on )
left outer join addr as c on a.addrid=c.id) left outer join code as d on a.codeid=d.id