មេរៀនទី២២: SQL Outer Join

មេរៀននេះ គ្រប់ដណ្តប់ ទាំង left outer join, right outer join, និង full outer join, វាមានភាពខុសគ្នា។
Left Outer Join ប្រើនេះ កាលណាលោកអ្នក ចង់ត្រឡប់ ទៅ rows ដែលមានទិន្នន័យ data នៅក្នុងតារាងខាងឆ្វេង table មិនមែន rows តារាងខាងស្តាំដៃ។
ឧទាហរណ៍ SQL statement
SELECT * FROM Individual AS Ind
LEFT JOIN Publisher AS Pub
ON Ind.IndividualId = Pub.IndividualId
ប្រភពតារាង Source Tables
តារាងខាងឆ្វេង Left Table
Id
FirstName
LastName
UserName
1 Fred Flinstone freddo
2 Homer Simpson homey
3 Homer Brown notsofamous
4 Ozzy Ozzbourne sabbath
5 Homer Gain noplacelike
តារាងខាងស្តាំ Right Table
IndividualId
AccessLevel
1 Administrator
2 Contributor
3 Contributor
4 Contributor
10 Administrator
លទ្ធផល
IndividualId
FirstName
LastName
UserName
IndividualId
AccessLevel
1 Fred Flinstone freddo 1 Administrator
2 Homer Simpson homey 2 Contributor
3 Homer Brown notsofamous 3 Contributor
4 Ozzy Osbourne sabbath 4 Contributor
5 Homer Gain noplacelike NULL NULL
Right Outer Join
កាលណាប្រើនេះ លោកអ្នកគ្រាន់តែចង់ ត្រឡប់ចូល rows ដែលទិន្នន័យខាងស្តាំក្នុងតារាងខាងស្តាំ  right table, សូម្បីតែ ប្រសិនបើមិនមាន rows ក្នុងតារាងខាងឆ្វេង left table.
ឧទាហរណ៍ SQL statement
SELECT * FROM Individual AS Ind
RIGHT JOIN Publisher AS Pub
ON Ind.IndividualId = Pub.IndividualId
Source Tables
តារាងឆ្វេង Left Table
Id
FirstName
LastName
UserName
1 Fred Flinstone freddo
2 Homer Simpson homey
3 Homer Brown notsofamous
4 Ozzy Ozzbourne sabbath
5 Homer Gain noplacelike
តារាងស្តាំ Right Table
IndividualId
AccessLevel
1 Administrator
2 Contributor
3 Contributor
4 Contributor
10 Administrator
លទ្ធផល
IndividualId
FirstName
LastName
UserName
IndividualId
AccessLevel
1 Fred Flinstone freddo 1 Administrator
2 Homer Simpson homey 2 Contributor
3 Homer Brown notsofamous 3 Contributor
4 Ozzy Osbourne sabbath 4 Contributor
NULL NULL NULL NULL 10 Administrator
Full Outer Join ប្រើនេះកាលណា លោកអ្នកចង់ទៅតារាង rows ទាំងអស់ ក្នុង right table។
ឧទាហរណ៍ SQL statement
SELECT * FROM Individual AS Ind
FULL JOIN Publisher AS Pub
ON Ind.IndividualId = Pub.IndividualId
ប្រភពតារាង Source Tables
តារាងឆ្វេង Left Table
Id
FirstName
LastName
UserName
1 Fred Flinstone freddo
2 Homer Simpson homey
3 Homer Brown notsofamous
4 Ozzy Ozzbourne sabbath
5 Homer Gain noplacelike
តារាងស្តាំ Right Table
IndividualId
AccessLevel
1 Administrator
2 Contributor
3 Contributor
4 Contributor
10 Administrator
លទ្ធផល
IndividualId
FirstName
LastName
UserName
IndividualId
AccessLevel
1 Fred Flinstone freddo 1 Administrator
2 Homer Simpson homey 2 Contributor
3 Homer Brown notsofamous 3 Contributor
4 Ozzy Osbourne sabbath 4 Contributor
5 Homer Gain noplacelike NULL NULL
NULL NULL NULL NULL 10 Administrator