더 많은 조인

Oracle SQL 입문

Sara Billen

Curriculum Manager

기타 조인 유형

  • CROSS JOIN
  • 셀프 JOIN
Oracle SQL 입문

카르테시안 곱(크로스 곱)

카르테시안 곱 다이어그램

Oracle SQL 입문

테이블에서의 크로스 곱

$$

테이블에서의 크로스 곱

Oracle SQL 입문

크로스 곱 예시

SELECT * 
FROM MediaType
| MediaTypeId | Name                        |
|-------------|-----------------------------|
| 1           | MPEG audio file             |
| 2           | Protected AAC audio file    |
| 3           | Protected MPEG-4 video file |
| 4           | Purchased AAC audio file    |
| 5           | AAC audio file              |
Oracle SQL 입문

크로스 곱 예시

SELECT m.MediaTypeId, m.Name, t.TrackId, t.Name, t.MediaTypeId
FROM MediaType m CROSS JOIN Track t
| MediaTypeId | Name                        | TrackId | Name       | MediaTypeId       |
|-------------|-----------------------------|---------|------------|-------------------|
| 1           | MPEG audio file             | 3021    | Forty      | 1                 |
| 2           | Protected AAC audio file    | 3021    | Forty      | 1                 |
| 3           | Protected MPEG-4 video file | 3021    | Forty      | 1                 |
| 4           | Purchased AAC audio file    | 3021    | Forty      | 1                 |
| 5           | AAC audio file              | 3021    | Forty      | 1                 |

Oracle SQL 입문

셀프 조인

  • 테이블을 자기 자신과 조인

사용 예:

SELECT * FROM Employee
| EmployeeId | LastName | Title               | ... | ReportsTo |
|------------|----------|---------------------|-----|-----------|
| 1          | Adames   | General Manager     | ... | null      |
| 2          | Edwards  | Sales Manager       | ... | 1         |
| 3          | Peacock  | Sales Support Agent | ... | 2         |
| 4          | Park     | Sales Support Agent | ... | 2         |

Oracle SQL 입문

셀프 조인

SELECT e.LastName Employee, m.LastName ReportsTo
FROM Employee e JOIN Employee m
ON (e.ReportsTo = m.EmployeeId)
| Employee | ReportsTo |
|----------|-----------|
| Edwards  | Adams     |
| Peacock  | Edwards   |
| Mitchell | Adams     |
| Park       | Edwards   |
| ...      | ...       |
Oracle SQL 입문

연습해 봅시다!

Oracle SQL 입문

Preparing Video For Download...