Home > database >  SQL SERVER Cross the apply and Outer real usage is the apply?
SQL SERVER Cross the apply and Outer real usage is the apply?

Time:12-04

/* Cross the apply and Outer real usage is the apply? 
With their inner join and what is the difference between the Left join, can use a simple example shows that, under the thank you very much
I simulation test under the Cross under the apply and inner join, Outer apply equivalent left associated */
Declare @ Studient table (PersonId varchar (50), PersonName Nvarchar (50))
Declare @ Score table (PersonId varchar (50), the Subject Nvarchar (50), Score INT)
INSERT INTO @ Studient
SELECT 'A01', 'zhang' union all
SELECT 'how A02', 'bill' union all
SELECT 'A05', 'Cathy'
INSERT INTO @ Score
SELECT 'A01', 'language', 90 union all
SELECT 'how A02', 'mathematics', 95 union all
SELECT 'A03', 'English', 100,

- CROSS the APPLY of the SELECT * FROM @ Studient A INNER JOIN @ Score ON p. B ersonId=Amy polumbo ersonId
SELECT * FROM @ Studient A
CROSS the APPLY
(SELECT * FROM @ Score B WHERE p. ersonId=Amy polumbo ersonId) C
/*
PersonId PersonName PersonId Subject Score
A01 zhang SAN A01 Chinese 90
How A02 li si how A02 math 95
*/

- outer apply equivalent LEFT JOIN
SELECT * FROM @ Studient A
The outer apply (SELECT * FROM @ Score B WHERE p. ersonId=Amy polumbo ersonId) C
/*
PersonId PersonName PersonId Subject Score
A01 zhang SAN A01 Chinese 90
How A02 li si how A02 math 95
A05 fifty and NULL NULL NULL
*/
  • Related