SQL 교차 조인

Jmnote (토론 | 기여)님의 2021년 7월 26일 (월) 01:25 판

1 개요

SQL cross join
SQL 교차 조인, 크로스 조인

2 예시 1

SELECT * FROM employee
SELECT * FROM department
SELECT *
FROM employee CROSS JOIN department
SELECT *
FROM employee, department

3 예시 2

CREATE TABLE Sales (Date date, CountryID int(11), Units int(11));
INSERT INTO Sales (Date, CountryID, Units) VALUES
	('2020-01-01', 1, 40),
	('2020-01-02', 1, 25),
	('2020-01-03', 3, 30),
	('2020-01-04', 4, 35);

CREATE TABLE Countries (ID int(11), Country varchar(16));
INSERT INTO Countries (ID, Country) VALUES
	(1, 'USA'),
	(2, 'Canada');

SELECT Sales.*, Countries.Country
FROM Sales CROSS JOIN Countries

4 같이 보기

5 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}