여러분이 사용하고 계신 브라우저는 HTML5를 지원하지 않기 때문에 몇몇 요소가 제대로 보이도록 JScript를 사용하고 있습니다. 하지만 여러분의 브라우저 설정에서 스크립트 기능이 꺼져있으므로, 현재 페이지를 제대로 확인하시려면 스크립트 기능을 켜주셔야 합니다. SQL - 참조 - 키워드 - JOIN
SQL – 참조 – 키워드 – JOIN
2년전 작성
1년전 수정

JOIN

INNER JOIN

INNER JOIN 명령은 두 테이블에서 일치하는 값이 있는 행을 반환한다.

예제
고객 정보가 있는 모든 주문을 선택한다.
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
기본 예시

OrderID CustomerName
10248 Wilman Kala
10249 Tradição Hipermercados
10250 Hanari Carnes
10251 Victuailles en stock
10252 Suprêmes délices
10253 Hanari Carnes
10254 Chop-suey Chinese
10255 Richter Supermarkt
10256 Wellington Importadora
10257 HILARIÓN-Abastos
10258 Ernst Handel
10259 Centro comercial Moctezuma
10260 Old World Delicatessen
10261 Que Delícia
10262 Rattlesnake Canyon Grocery
10263 Ernst Handel
10264 Folk och fä HB
10265 Blondel père et fils
10266 Wartian Herkku
10267 Frankenversand
10268 GROSELLA-Restaurante
10269 White Clover Markets
10270 Wartian Herkku
10271 Split Rail Beer & Ale
10272 Rattlesnake Canyon Grocery
10273 QUICK-Stop
10274 Vins et alcools Chevalier
10275 Magazzini Alimentari Riuniti
10276 Tortuga Restaurante
10277 Morgenstern Gesundkost
10278 Berglunds snabbköp
10279 Lehmanns Marktstand
10280 Berglunds snabbköp
10281 Romero y tomillo
10282 Romero y tomillo
10283 LILA-Supermercado
10284 Lehmanns Marktstand
10285 QUICK-Stop
10286 QUICK-Stop
10287 Ricardo Adocicados
10288 Reggiani Caseifici
10289 B’s Beverages
10290 Comércio Mineiro
10291 Que Delícia
10292 Tradição Hipermercados
10293 Tortuga Restaurante
10294 Rattlesnake Canyon Grocery
10295 Vins et alcools Chevalier
10296 LILA-Supermercado
10297 Blondel père et fils
10298 Hungry Owl All-Night Grocers
10299 Ricardo Adocicados
10300 Magazzini Alimentari Riuniti
10301 Die Wandernde Kuh
10302 Suprêmes délices
10303 Godos Cocina Típica
10304 Tortuga Restaurante
10305 Old World Delicatessen
10306 Romero y tomillo
10307 Lonesome Pine Restaurant
10308 Ana Trujillo Emparedados y helados
10309 Hungry Owl All-Night Grocers
10310 The Big Cheese
10311 Du monde entier
10312 Die Wandernde Kuh
10313 QUICK-Stop
10314 Rattlesnake Canyon Grocery
10315 Island Trading
10316 Rattlesnake Canyon Grocery
10317 Lonesome Pine Restaurant
10318 Island Trading
10319 Tortuga Restaurante
10320 Wartian Herkku
10321 Island Trading
10322 Pericles Comidas clásicas
10323 Königlich Essen
10324 Save-a-lot Markets
10325 Königlich Essen
10326 Bólido Comidas preparadas
10327 Folk och fä HB
10328 Furia Bacalhau e Frutos do Mar
10329 Split Rail Beer & Ale
10330 LILA-Supermercado
10331 Bon app’
10332 Mère Paillarde
10333 Wartian Herkku
10334 Victuailles en stock
10335 Hungry Owl All-Night Grocers
10336 Princesa Isabel Vinhoss
10337 Frankenversand
10338 Old World Delicatessen
10339 Mère Paillarde
10340 Bon app’
10341 Simons bistro
10342 Frankenversand
10343 Lehmanns Marktstand
10344 White Clover Markets
10345 QUICK-Stop
10346 Rattlesnake Canyon Grocery
10347 Familia Arquibaldo
10348 Die Wandernde Kuh
10349 Split Rail Beer & Ale
10350 La maison d’Asie
10351 Ernst Handel
10352 Furia Bacalhau e Frutos do Mar
10353 Piccolo und mehr
10354 Pericles Comidas clásicas
10355 Around the Horn
10356 Die Wandernde Kuh
10357 LILA-Supermercado
10358 La maison d’Asie
10359 Seven Seas Imports
10360 Blondel père et fils
10361 QUICK-Stop
10362 Bon app’
10363 Drachenblut Delikatessend
10364 Eastern Connection
10365 Antonio Moreno Taquería
10366 Galería del gastrónomo
10367 Vaffeljernet
10368 Ernst Handel
10369 Split Rail Beer & Ale
10370 Chop-suey Chinese
10371 La maison d’Asie
10372 Queen Cozinha
10373 Hungry Owl All-Night Grocers
10374 Wolski
10375 Hungry Coyote Import Store
10376 Mère Paillarde
10377 Seven Seas Imports
10378 Folk och fä HB
10379 Que Delícia
10380 Hungry Owl All-Night Grocers
10381 LILA-Supermercado
10382 Ernst Handel
10383 Around the Horn
10384 Berglunds snabbköp
10385 Split Rail Beer & Ale
10386 Familia Arquibaldo
10387 Santé Gourmet
10388 Seven Seas Imports
10389 Bottom-Dollar Marketse
10390 Ernst Handel
10391 Drachenblut Delikatessend
10392 Piccolo und mehr
10393 Save-a-lot Markets
10394 Hungry Coyote Import Store
10395 HILARIÓN-Abastos
10396 Frankenversand
10397 Princesa Isabel Vinhoss
10398 Save-a-lot Markets
10399 Vaffeljernet
10400 Eastern Connection
10401 Rattlesnake Canyon Grocery
10402 Ernst Handel
10403 Ernst Handel
10404 Magazzini Alimentari Riuniti
10405 LINO-Delicateses
10406 Queen Cozinha
10407 Ottilies Käseladen
10408 Folies gourmandes
10409 Océano Atlántico Ltda.
10410 Bottom-Dollar Marketse
10411 Bottom-Dollar Marketse
10412 Wartian Herkku
10413 La maison d’Asie
10414 Familia Arquibaldo
10415 Hungry Coyote Import Store
10416 Wartian Herkku
10417 Simons bistro
10418 QUICK-Stop
10419 Richter Supermarkt
10420 Wellington Importadora
10421 Que Delícia
10422 Franchi S.p.A.
10423 Gourmet Lanchonetes
10424 Mère Paillarde
10425 La maison d’Asie
10426 Galería del gastrónomo
10427 Piccolo und mehr
10428 Reggiani Caseifici
10429 Hungry Owl All-Night Grocers
10430 Ernst Handel
10431 Bottom-Dollar Marketse
10432 Split Rail Beer & Ale
10433 Princesa Isabel Vinhoss
10434 Folk och fä HB
10435 Consolidated Holdings
10436 Blondel père et fils
10437 Wartian Herkku
10438 Toms Spezialitäten
10439 Mère Paillarde
10440 Save-a-lot Markets
10441 Old World Delicatessen
10442 Ernst Handel
10443 Reggiani Caseifici

INNER JOIN 키워드는 열 간에 일치하는 항목이 있는 한 두 테이블의 모든 행을 선택한다.
“Customers”와 일치하지 않는 레코드가 “Orders” 테이블에 있는 경우 이러한 주문은 표시되지 않는다.

고객 및 배송업체 정보가 있는 모든 주문을 선택한다.
SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName
FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);
기본 예시

OrderID CustomerName ShipperName
10248 Wilman Kala Federal Shipping
10249 Tradição Hipermercados Speedy Express
10250 Hanari Carnes United Package
10251 Victuailles en stock Speedy Express
10252 Suprêmes délices United Package
10253 Hanari Carnes United Package
10254 Chop-suey Chinese United Package
10255 Richter Supermarkt Federal Shipping
10256 Wellington Importadora United Package
10257 HILARIÓN-Abastos Federal Shipping
10258 Ernst Handel Speedy Express
10259 Centro comercial Moctezuma Federal Shipping
10260 Old World Delicatessen Speedy Express
10261 Que Delícia United Package
10262 Rattlesnake Canyon Grocery Federal Shipping
10263 Ernst Handel Federal Shipping
10264 Folk och fä HB Federal Shipping
10265 Blondel père et fils Speedy Express
10266 Wartian Herkku Federal Shipping
10267 Frankenversand Speedy Express
10268 GROSELLA-Restaurante Federal Shipping
10269 White Clover Markets Speedy Express
10270 Wartian Herkku Speedy Express
10271 Split Rail Beer & Ale United Package
10272 Rattlesnake Canyon Grocery United Package
10273 QUICK-Stop Federal Shipping
10274 Vins et alcools Chevalier Speedy Express
10275 Magazzini Alimentari Riuniti Speedy Express
10276 Tortuga Restaurante Federal Shipping
10277 Morgenstern Gesundkost Federal Shipping
10278 Berglunds snabbköp United Package
10279 Lehmanns Marktstand United Package
10280 Berglunds snabbköp Speedy Express
10281 Romero y tomillo Speedy Express
10282 Romero y tomillo Speedy Express
10283 LILA-Supermercado Federal Shipping
10284 Lehmanns Marktstand Speedy Express
10285 QUICK-Stop United Package
10286 QUICK-Stop Federal Shipping
10287 Ricardo Adocicados Federal Shipping
10288 Reggiani Caseifici Speedy Express
10289 B’s Beverages Federal Shipping
10290 Comércio Mineiro Speedy Express
10291 Que Delícia United Package
10292 Tradição Hipermercados United Package
10293 Tortuga Restaurante Federal Shipping
10294 Rattlesnake Canyon Grocery United Package
10295 Vins et alcools Chevalier United Package
10296 LILA-Supermercado Speedy Express
10297 Blondel père et fils United Package
10298 Hungry Owl All-Night Grocers United Package
10299 Ricardo Adocicados United Package
10300 Magazzini Alimentari Riuniti United Package
10301 Die Wandernde Kuh United Package
10302 Suprêmes délices United Package
10303 Godos Cocina Típica United Package
10304 Tortuga Restaurante United Package
10305 Old World Delicatessen Federal Shipping
10306 Romero y tomillo Federal Shipping
10307 Lonesome Pine Restaurant United Package
10308 Ana Trujillo Emparedados y helados Federal Shipping
10309 Hungry Owl All-Night Grocers Speedy Express
10310 The Big Cheese United Package
10311 Du monde entier Federal Shipping
10312 Die Wandernde Kuh United Package
10313 QUICK-Stop United Package
10314 Rattlesnake Canyon Grocery United Package
10315 Island Trading United Package
10316 Rattlesnake Canyon Grocery Federal Shipping
10317 Lonesome Pine Restaurant Speedy Express
10318 Island Trading United Package
10319 Tortuga Restaurante Federal Shipping
10320 Wartian Herkku Federal Shipping
10321 Island Trading United Package
10322 Pericles Comidas clásicas Federal Shipping
10323 Königlich Essen Speedy Express
10324 Save-a-lot Markets Speedy Express
10325 Königlich Essen Federal Shipping
10326 Bólido Comidas preparadas United Package
10327 Folk och fä HB Speedy Express
10328 Furia Bacalhau e Frutos do Mar Federal Shipping
10329 Split Rail Beer & Ale United Package
10330 LILA-Supermercado Speedy Express
10331 Bon app’ Speedy Express
10332 Mère Paillarde United Package
10333 Wartian Herkku Federal Shipping
10334 Victuailles en stock United Package
10335 Hungry Owl All-Night Grocers United Package
10336 Princesa Isabel Vinhoss United Package
10337 Frankenversand Federal Shipping
10338 Old World Delicatessen Federal Shipping
10339 Mère Paillarde United Package
10340 Bon app’ Federal Shipping
10341 Simons bistro Federal Shipping
10342 Frankenversand United Package
10343 Lehmanns Marktstand Speedy Express
10344 White Clover Markets United Package
10345 QUICK-Stop United Package
10346 Rattlesnake Canyon Grocery Federal Shipping
10347 Familia Arquibaldo Federal Shipping
10348 Die Wandernde Kuh United Package
10349 Split Rail Beer & Ale Speedy Express
10350 La maison d’Asie United Package
10351 Ernst Handel Speedy Express
10352 Furia Bacalhau e Frutos do Mar Federal Shipping
10353 Piccolo und mehr Federal Shipping
10354 Pericles Comidas clásicas Federal Shipping
10355 Around the Horn Speedy Express
10356 Die Wandernde Kuh United Package
10357 LILA-Supermercado Federal Shipping
10358 La maison d’Asie Speedy Express
10359 Seven Seas Imports Federal Shipping
10360 Blondel père et fils Federal Shipping
10361 QUICK-Stop United Package
10362 Bon app’ Speedy Express
10363 Drachenblut Delikatessend Federal Shipping
10364 Eastern Connection Speedy Express
10365 Antonio Moreno Taquería United Package
10366 Galería del gastrónomo United Package
10367 Vaffeljernet Federal Shipping
10368 Ernst Handel United Package
10369 Split Rail Beer & Ale United Package
10370 Chop-suey Chinese United Package
10371 La maison d’Asie Speedy Express
10372 Queen Cozinha United Package
10373 Hungry Owl All-Night Grocers Federal Shipping
10374 Wolski Federal Shipping
10375 Hungry Coyote Import Store United Package
10376 Mère Paillarde United Package
10377 Seven Seas Imports Federal Shipping
10378 Folk och fä HB Federal Shipping
10379 Que Delícia Speedy Express
10380 Hungry Owl All-Night Grocers Federal Shipping
10381 LILA-Supermercado Federal Shipping
10382 Ernst Handel Speedy Express
10383 Around the Horn Federal Shipping
10384 Berglunds snabbköp Federal Shipping
10385 Split Rail Beer & Ale United Package
10386 Familia Arquibaldo Federal Shipping
10387 Santé Gourmet United Package
10388 Seven Seas Imports Speedy Express
10389 Bottom-Dollar Marketse United Package
10390 Ernst Handel Speedy Express
10391 Drachenblut Delikatessend Federal Shipping
10392 Piccolo und mehr Federal Shipping
10393 Save-a-lot Markets Federal Shipping
10394 Hungry Coyote Import Store Federal Shipping
10395 HILARIÓN-Abastos Speedy Express
10396 Frankenversand Federal Shipping
10397 Princesa Isabel Vinhoss Speedy Express
10398 Save-a-lot Markets Federal Shipping
10399 Vaffeljernet Federal Shipping
10400 Eastern Connection Federal Shipping
10401 Rattlesnake Canyon Grocery Speedy Express
10402 Ernst Handel United Package
10403 Ernst Handel Federal Shipping
10404 Magazzini Alimentari Riuniti Speedy Express
10405 LINO-Delicateses Speedy Express
10406 Queen Cozinha Speedy Express
10407 Ottilies Käseladen United Package
10408 Folies gourmandes Speedy Express
10409 Océano Atlántico Ltda. Speedy Express
10410 Bottom-Dollar Marketse Federal Shipping
10411 Bottom-Dollar Marketse Federal Shipping
10412 Wartian Herkku United Package
10413 La maison d’Asie United Package
10414 Familia Arquibaldo Federal Shipping
10415 Hungry Coyote Import Store Speedy Express
10416 Wartian Herkku Federal Shipping
10417 Simons bistro Federal Shipping
10418 QUICK-Stop Speedy Express
10419 Richter Supermarkt United Package
10420 Wellington Importadora Speedy Express
10421 Que Delícia Speedy Express
10422 Franchi S.p.A. Speedy Express
10423 Gourmet Lanchonetes Federal Shipping
10424 Mère Paillarde United Package
10425 La maison d’Asie United Package
10426 Galería del gastrónomo Speedy Express
10427 Piccolo und mehr United Package
10428 Reggiani Caseifici Speedy Express
10429 Hungry Owl All-Night Grocers United Package
10430 Ernst Handel Speedy Express
10431 Bottom-Dollar Marketse United Package
10432 Split Rail Beer & Ale United Package
10433 Princesa Isabel Vinhoss Federal Shipping
10434 Folk och fä HB United Package
10435 Consolidated Holdings United Package
10436 Blondel père et fils United Package
10437 Wartian Herkku Speedy Express
10438 Toms Spezialitäten United Package
10439 Mère Paillarde Federal Shipping
10440 Save-a-lot Markets United Package
10441 Old World Delicatessen United Package
10442 Ernst Handel United Package
10443 Reggiani Caseifici Speedy Express

LEFT JOIN

왼쪽 테이블의 모든 행과 오른쪽 테이블의 일치하는 행을 반환한다.
일치하는 항목이 없으면 결과는 오른쪽에서 NULL이다.

예제
모든 고객과 그들이 가질 수 있는 모든 주문을 선택한다.
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
기본 예시

CustomerName OrderID
Alfreds Futterkiste null
Ana Trujillo Emparedados y helados 10308
Antonio Moreno Taquería 10365
Around the Horn 10355
Around the Horn 10383
B’s Beverages 10289
Berglunds snabbköp 10278
Berglunds snabbköp 10280
Berglunds snabbköp 10384
Blauer See Delikatessen null
Blondel père et fils 10265
Blondel père et fils 10297
Blondel père et fils 10360
Blondel père et fils 10436
Bon app’ 10331
Bon app’ 10340
Bon app’ 10362
Bottom-Dollar Marketse 10389
Bottom-Dollar Marketse 10410
Bottom-Dollar Marketse 10411
Bottom-Dollar Marketse 10431
Bólido Comidas preparadas 10326
Cactus Comidas para llevar null
Centro comercial Moctezuma 10259
Chop-suey Chinese 10254
Chop-suey Chinese 10370
Comércio Mineiro 10290
Consolidated Holdings 10435
Die Wandernde Kuh 10301
Die Wandernde Kuh 10312
Die Wandernde Kuh 10348
Die Wandernde Kuh 10356
Drachenblut Delikatessend 10363
Drachenblut Delikatessend 10391
Du monde entier 10311
Eastern Connection 10364
Eastern Connection 10400
Ernst Handel 10258
Ernst Handel 10263
Ernst Handel 10351
Ernst Handel 10368
Ernst Handel 10382
Ernst Handel 10390
Ernst Handel 10402
Ernst Handel 10403
Ernst Handel 10430
Ernst Handel 10442
FISSA Fabrica Inter. Salchichas S.A. null
Familia Arquibaldo 10347
Familia Arquibaldo 10386
Familia Arquibaldo 10414
Folies gourmandes 10408
Folk och fä HB 10264
Folk och fä HB 10327
Folk och fä HB 10378
Folk och fä HB 10434
France restauration null
Franchi S.p.A. 10422
Frankenversand 10267
Frankenversand 10337
Frankenversand 10342
Frankenversand 10396
Furia Bacalhau e Frutos do Mar 10328
Furia Bacalhau e Frutos do Mar 10352
GROSELLA-Restaurante 10268
Galería del gastrónomo 10366
Galería del gastrónomo 10426
Godos Cocina Típica 10303
Gourmet Lanchonetes 10423
Great Lakes Food Market null
HILARIÓN-Abastos 10257
HILARIÓN-Abastos 10395
Hanari Carnes 10250
Hanari Carnes 10253
Hungry Coyote Import Store 10375
Hungry Coyote Import Store 10394
Hungry Coyote Import Store 10415
Hungry Owl All-Night Grocers 10298
Hungry Owl All-Night Grocers 10309
Hungry Owl All-Night Grocers 10335
Hungry Owl All-Night Grocers 10373
Hungry Owl All-Night Grocers 10380
Hungry Owl All-Night Grocers 10429
Island Trading 10315
Island Trading 10318
Island Trading 10321
Königlich Essen 10323
Königlich Essen 10325
LILA-Supermercado 10283
LILA-Supermercado 10296
LILA-Supermercado 10330
LILA-Supermercado 10357
LILA-Supermercado 10381
LINO-Delicateses 10405
La corne d’abondance null
La maison d’Asie 10350
La maison d’Asie 10358
La maison d’Asie 10371
La maison d’Asie 10413
La maison d’Asie 10425
Laughing Bacchus Wine Cellars null
Lazy K Kountry Store null
Lehmanns Marktstand 10279
Lehmanns Marktstand 10284
Lehmanns Marktstand 10343
Let’s Stop N Shop null
Lonesome Pine Restaurant 10307
Lonesome Pine Restaurant 10317
Magazzini Alimentari Riuniti 10275
Magazzini Alimentari Riuniti 10300
Magazzini Alimentari Riuniti 10404
Maison Dewey null
Morgenstern Gesundkost 10277
Mère Paillarde 10332
Mère Paillarde 10339
Mère Paillarde 10376
Mère Paillarde 10424
Mère Paillarde 10439
North/South null
Océano Atlántico Ltda. 10409
Old World Delicatessen 10260
Old World Delicatessen 10305
Old World Delicatessen 10338
Old World Delicatessen 10441
Ottilies Käseladen 10407
Paris spécialités null
Pericles Comidas clásicas 10322
Pericles Comidas clásicas 10354
Piccolo und mehr 10353
Piccolo und mehr 10392
Piccolo und mehr 10427
Princesa Isabel Vinhoss 10336
Princesa Isabel Vinhoss 10397
Princesa Isabel Vinhoss 10433
QUICK-Stop 10273
QUICK-Stop 10285
QUICK-Stop 10286
QUICK-Stop 10313
QUICK-Stop 10345
QUICK-Stop 10361
QUICK-Stop 10418
Que Delícia 10261
Que Delícia 10291
Que Delícia 10379
Que Delícia 10421
Queen Cozinha 10372
Queen Cozinha 10406
Rancho grande null
Rattlesnake Canyon Grocery 10262
Rattlesnake Canyon Grocery 10272
Rattlesnake Canyon Grocery 10294
Rattlesnake Canyon Grocery 10314
Rattlesnake Canyon Grocery 10316
Rattlesnake Canyon Grocery 10346
Rattlesnake Canyon Grocery 10401
Reggiani Caseifici 10288
Reggiani Caseifici 10428
Reggiani Caseifici 10443
Ricardo Adocicados 10287
Ricardo Adocicados 10299
Richter Supermarkt 10255
Richter Supermarkt 10419
Romero y tomillo 10281
Romero y tomillo 10282
Romero y tomillo 10306
Santé Gourmet 10387
Save-a-lot Markets 10324
Save-a-lot Markets 10393
Save-a-lot Markets 10398
Save-a-lot Markets 10440
Seven Seas Imports 10359
Seven Seas Imports 10377
Seven Seas Imports 10388
Simons bistro 10341
Simons bistro 10417
Split Rail Beer & Ale 10271
Split Rail Beer & Ale 10329
Split Rail Beer & Ale 10349
Split Rail Beer & Ale 10369
Split Rail Beer & Ale 10385
Split Rail Beer & Ale 10432
Spécialités du monde null
Suprêmes délices 10252
Suprêmes délices 10302
The Big Cheese 10310
The Cracker Box null
Toms Spezialitäten 10438
Tortuga Restaurante 10276
Tortuga Restaurante 10293
Tortuga Restaurante 10304
Tortuga Restaurante 10319
Tradição Hipermercados 10249
Tradição Hipermercados 10292
Trail’s Head Gourmet Provisioners null
Vaffeljernet 10367
Vaffeljernet 10399
Victuailles en stock 10251
Victuailles en stock 10334
Vins et alcools Chevalier 10274
Vins et alcools Chevalier 10295
Wartian Herkku 10266
Wartian Herkku 10270
Wartian Herkku 10320
Wartian Herkku 10333
Wartian Herkku 10412
Wartian Herkku 10416
Wartian Herkku 10437
Wellington Importadora 10256
Wellington Importadora 10420
White Clover Markets 10269
White Clover Markets 10344
Wilman Kala 10248
Wolski 10374

오른쪽 테이블(Orders)에 일치 항목이 없더라도 왼쪽 테이블(Customers)의 모든 레코드를 반환한다.

RIGHT JOIN

오른쪽 테이블의 모든 행과 왼쪽 테이블의 일치하는 레코드를 반환한다.
결과는 일치하는 항목이 없을 때 왼쪽부터 NULL이다.

예제
모든 직원과 직원이 발주한 모든 주문을 반환한다.
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
기본 예시

OrderID LastName FirstName
  West  Adam 
10248  Buchanan  Steven 
10249  Suyama  Michael 
10250  Peacock  Margaret 
10251  Leverling  Janet 
10252  Peacock  Margaret 
10253  Leverling  Janet 
10254  Buchanan  Steven 
10255  Dodsworth  Anne 
10256  Leverling  Janet 
10257  Peacock  Margaret 
10258  Davolio  Nancy 
10259  Peacock  Margaret 
10260  Peacock  Margaret 
10261  Peacock  Margaret 
10262  Callahan  Laura 
10263  Dodsworth  Anne 
10264  Suyama  Michael 
10265  Fuller  Andrew 
10266  Leverling  Janet 
10267  Peacock  Margaret 
10268  Callahan  Laura 
10269  Buchanan  Steven 
10270  Davolio  Nancy 
10271  Suyama  Michael 
10272  Suyama  Michael 
10273  Leverling  Janet 
10274  Suyama  Michael 
10275  Davolio  Nancy 
10276  Callahan  Laura 
10277  Fuller  Andrew 
10278  Callahan  Laura 
10279  Callahan  Laura 
10280  Fuller  Andrew 
10281  Peacock  Margaret 
10282  Peacock  Margaret 
10283  Leverling  Janet 
10284  Peacock  Margaret 
10285  Davolio  Nancy 
10286  Callahan  Laura 
10287  Callahan  Laura 
10288  Peacock  Margaret 
10289  King  Robert 
10290  Callahan  Laura 
10291  Suyama  Michael 
10292  Davolio  Nancy 
10293  Davolio  Nancy 
10294  Peacock  Margaret 
10295  Fuller  Andrew 
10296  Suyama  Michael 
10297  Buchanan  Steven 
10298  Suyama  Michael 
10299  Peacock  Margaret 
10300  Fuller  Andrew 
10301  Callahan  Laura 
10302  Peacock  Margaret 
10303  King  Robert 
10304  Davolio  Nancy 
10305  Callahan  Laura 
10306  Davolio  Nancy 
10307  Fuller  Andrew 
10308  King  Robert 
10309  Leverling  Janet 
10310  Callahan  Laura 
10311  Davolio  Nancy 
10312  Fuller  Andrew 
10313  Fuller  Andrew 
10314  Davolio  Nancy 
10315  Peacock  Margaret 
10316  Davolio  Nancy 
10317  Suyama  Michael 
10318  Callahan  Laura 
10319  King  Robert 
10320  Buchanan  Steven 
10321  Leverling  Janet 
10322  King  Robert 
10323  Peacock  Margaret 
10324  Dodsworth  Anne 
10325  Davolio  Nancy 
10326  Peacock  Margaret 
10327  Fuller  Andrew 
10328  Peacock  Margaret 
10329  Peacock  Margaret 
10330  Leverling  Janet 
10331  Dodsworth  Anne 
10332  Leverling  Janet 
10333  Buchanan  Steven 
10334  Callahan  Laura 
10335  King  Robert 
10336  King  Robert 
10337  Peacock  Margaret 
10338  Peacock  Margaret 
10339  Fuller  Andrew 
10340  Davolio  Nancy 
10341  King  Robert 
10342  Peacock  Margaret 
10343  Peacock  Margaret 
10344  Peacock  Margaret 
10345  Fuller  Andrew 
10346  Leverling  Janet 
10347  Peacock  Margaret 
10348  Peacock  Margaret 
10349  King  Robert 
10350  Suyama  Michael 
10351  Davolio  Nancy 
10352  Leverling  Janet 
10353  King  Robert 
10354  Callahan  Laura 
10355  Suyama  Michael 
10356  Suyama  Michael 
10357  Davolio  Nancy 
10358  Buchanan  Steven 
10359  Buchanan  Steven 
10360  Peacock  Margaret 
10361  Davolio  Nancy 
10362  Leverling  Janet 
10363  Peacock  Margaret 
10364  Davolio  Nancy 
10365  Leverling  Janet 
10366  Callahan  Laura 
10367  King  Robert 
10368  Fuller  Andrew 
10369  Callahan  Laura 
10370  Suyama  Michael 
10371  Davolio  Nancy 
10372  Buchanan  Steven 
10373  Peacock  Margaret 
10374  Davolio  Nancy 
10375  Leverling  Janet 
10376  Davolio  Nancy 
10377  Davolio  Nancy 
10378  Buchanan  Steven 
10379  Fuller  Andrew 
10380  Callahan  Laura 
10381  Leverling  Janet 
10382  Peacock  Margaret 
10383  Callahan  Laura 
10384  Leverling  Janet 
10385  Davolio  Nancy 
10386  Dodsworth  Anne 
10387  Davolio  Nancy 
10388  Fuller  Andrew 
10389  Peacock  Margaret 
10390  Suyama  Michael 
10391  Leverling  Janet 
10392  Fuller  Andrew 
10393  Davolio  Nancy 
10394  Davolio  Nancy 
10395  Suyama  Michael 
10396  Davolio  Nancy 
10397  Buchanan  Steven 
10398  Fuller  Andrew 
10399  Callahan  Laura 
10400  Davolio  Nancy 
10401  Davolio  Nancy 
10402  Callahan  Laura 
10403  Peacock  Margaret 
10404  Fuller  Andrew 
10405  Davolio  Nancy 
10406  King  Robert 
10407  Fuller  Andrew 
10408  Callahan  Laura 
10409  Leverling  Janet 
10410  Leverling  Janet 
10411  Dodsworth  Anne 
10412  Callahan  Laura 
10413  Leverling  Janet 
10414  Fuller  Andrew 
10415  Leverling  Janet 
10416  Callahan  Laura 
10417  Peacock  Margaret 
10418  Peacock  Margaret 
10419  Peacock  Margaret 
10420  Leverling  Janet 
10421  Callahan  Laura 
10422  Fuller  Andrew 
10423  Suyama  Michael 
10424  King  Robert 
10425  Suyama  Michael 
10426  Peacock  Margaret 
10427  Peacock  Margaret 
10428  King  Robert 
10429  Leverling  Janet 
10430  Peacock  Margaret 
10431  Peacock  Margaret 
10432  Leverling  Janet 
10433  Leverling  Janet 
10434  Leverling  Janet 
10435  Callahan  Laura 
10436  Leverling  Janet 
10437  Callahan  Laura 
10438  Leverling  Janet 
10439  Suyama  Michael 
10440  Peacock  Margaret 
10441  Leverling  Janet 
10442  Leverling  Janet 
10443  Callahan  Laura 

왼쪽 테이블(Orders)에 일치 항목이 없더라도 오른쪽 테이블(Employees)의 모든 레코드를 반환한다.

FULL OUTER JOIN

왼쪽 테이블이나 오른쪽 테이블에 일치 항목이 있을 때 모든 행을 반환한다.

예제
모든 고객 및 모든 주문을 선택한다.
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName;

왼쪽 테이블(Customers)의 모든 행과 오른쪽 테이블(Orders)의 모든 행을 반환한다.
“Customers”에 “Orders”와 일치하지 않는 행이 있거나 “Customers”와 일치하지 않는 “Orders”에 행이 있는 경우 해당 행도 나열된다.

참고

Mingg`s Diary
밍구
밍구
공부 목적 블로그