-
Notifications
You must be signed in to change notification settings - Fork 0
/
RIGHT JOIN.sql
42 lines (36 loc) · 993 Bytes
/
RIGHT JOIN.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
USE AdventureWorks2022
GO
-- SELECT * FROM Sales.SalesPerson -- 17
-- Manteve 17 linhas, porque usei o JOIN (Ou innner join)
-- logo ele manteve o que é intersecção entre as 2 tabelas
SELECT
SSP.BusinessEntityID AS [SSP.BusinessEntityID],
PP.BusinessEntityID AS [PP.BusinessEntityID],
TerritoryID,
SalesQuota,
Bonus,
SalesLastYear,
FirstName,
MiddleName,
LastName
FROM Sales.SalesPerson AS SSP
JOIN Person.Person AS PP
ON SSP.BusinessEntityID = PP.BusinessEntityID
SELECT
SSP.BusinessEntityID AS [SSP.BusinessEntityID],
PP.BusinessEntityID AS [PP.BusinessEntityID],
TerritoryID,
SalesQuota,
Bonus,
SalesLastYear,
FirstName,
MiddleName,
LastName,
EmailAddress
FROM Sales.SalesPerson AS SSP
RIGHT JOIN Person.Person AS PP
ON SSP.BusinessEntityID = PP.BusinessEntityID
RIGHT JOIN Person.EmailAddress as PEA
ON PEA.BusinessEntityID = PP.BusinessEntityID
ORDER BY SSP.BusinessEntityID,
PP.BusinessEntityID