什么时候应该在内部连接上使用交叉应用?
cross apply
CROSS APPLY
INNER JOIN
CROSS APPLY
CROSS APPLY
INNER JOIN
编辑:
cross apply
create table Company ( companyId int identity(1,1), companyName varchar(100), zipcode varchar(10) , constraint PK_Company primary key (companyId))GOcreate table Person ( personId int identity(1,1), personName varchar(100), companyId int, constraint FK_Person_CompanyId foreign key (companyId) references dbo.Company(companyId), constraint PK_Person primary key (personId))GOinsert Companyselect 'ABC Company', '19808' unionselect 'XYZ Company', '08534' unionselect '123 Company', '10016'insert Personselect 'Alan', 1 unionselect 'Bobby', 1 unionselect 'Chris', 1 unionselect 'Xavier', 2 unionselect 'Yoshi', 2 unionselect 'Zambrano', 2 unionselect 'Player 1', 3 unionselect 'Player 2', 3 unionselect 'Player 3', 3 /* using CROSS APPLY */select *from Person pcross apply ( select * from Company c where p.companyid = c.companyId) Czip/* the equivalent query using INNER JOIN */select *from Person pinner join Company c on p.companyid = c.companyId
翻翻过去那场雪
相关分类