CROSS JOIN 살펴보기

SQL에서 데이터 조인하기

Maham Faisal Khan

Senior Content Developer, DataCamp

CROSS JOIN 다이어그램

CROSS JOIN은 두 테이블의 모든 가능한 조합을 생성함.

A diagram showing two tables, table1 and table2, with arrows pointing to the records that match on the id column in both tables. Records that are not of interest to cross join have been grayed out. The result set after cross join is shown on the right hand side of the diagram.

SQL에서 데이터 조인하기

CROSS JOIN 구문

SELECT id1, id2
FROM table1
CROSS JOIN table2;
SQL에서 데이터 조인하기

총리와 대통령 매칭하기

SELECT prime_minister, president
FROM prime_ministers AS p1
CROSS JOIN presidents AS p2

WHERE p1.continent IN ('Asia') AND p2.continent IN ('South America');
|--------------------|-------------------------|
| prime_minister     | president               |
|--------------------|-------------------------|
| Shehbaz Sharif     | Luis Lacalle Pou        |
| Narendra Modi      | Luis Lacalle Pou        |
| Hassanal Bolkiah   | Luis Lacalle Pou        |
| Haitham bin Tarik  | Luis Lacalle Pou        |
| Shehbaz Sharif     | Gabriel Boric           |
| Narendra Modi      | Gabriel Boric           |
| Hassanal Bolkiah   | Gabriel Boric           |
| Haitham bin Tarik  | Gabriel Boric           |
|--------------------|-------------------------|
SQL에서 데이터 조인하기

연습해봅시다!

SQL에서 데이터 조인하기

Preparing Video For Download...