" /> sql - Quelle est la différence entre "INNER JOIN" et "OUTER JOIN" | 2022 codeprofesseur

sql - Quelle est la différence entre "INNER JOIN" et "OUTER JOIN"

Mots clés : sqldatabasejoininner-joinouter-joinsql

meilleur 3 Réponses sql - Quelle est la différence entre "INNER JOIN" et "OUTER JOIN"

vote vote

93

A    B -    - 1    3 2    4 3    5 4    6 
select * from a INNER JOIN b on a.a = b.b; select a.*, b.*  from a,b where a.a = b.b;  a | b --+-- 3 | 3 4 | 4 
select * from a LEFT OUTER JOIN b on a.a = b.b; select a.*, b.*  from a,b where a.a = b.b(+);  a |  b --+----- 1 | null 2 | null 3 |    3 4 |    4 
select * from a RIGHT OUTER JOIN b on a.a = b.b; select a.*, b.*  from a,b where a.a(+) = b.b;  a    |  b -----+---- 3    |  3 4    |  4 null |  5 null |  6 
select * from a FULL OUTER JOIN b on a.a = b.b;   a   |  b -----+-----    1 | null    2 | null    3 |    3    4 |    4 null |    6 null |    5 
vote vote

87

select  * from employee inner join location on employee.empID = location.empID OR select  * from employee, location where employee.empID = location.empID 
select  * from employee left outer join location on employee.empID = location.empID; //Use of outer keyword is optional 
select * from employee right outer join location  on employee.empID = location.empID; //Use of outer keyword is optional 
vote vote

77

SELECT * FROM dbo.Students S INNER JOIN dbo.Advisors A     ON S.Advisor_ID = A.Advisor_ID 
SELECT * FROM dbo.Students S LEFT JOIN dbo.Advisors A     ON S.Advisor_ID = A.Advisor_ID 
SELECT * FROM dbo.Students S FULL JOIN dbo.Advisors A     ON S.Advisor_ID = A.Advisor_ID 

Questions similaires