"SQL 오른쪽 조인"의 두 판 사이의 차이

잔글 (봇: JOIN을(를) 조인(으)로 분류 대체함)
 
(다른 사용자 한 명의 중간 판 5개는 보이지 않습니다)
17번째 줄: 17번째 줄:
</syntaxhighlight>
</syntaxhighlight>


==예시==
==예시 1==
{| class='w-100'
|class="align-top"|
<syntaxhighlight lang='mysql' run>
<syntaxhighlight lang='mysql' run>
SELECT * FROM employee
SELECT * FROM employee
</syntaxhighlight>
</syntaxhighlight>
|class="align-top"|
<syntaxhighlight lang='mysql' run>
<syntaxhighlight lang='mysql' run>
SELECT * FROM department
SELECT * FROM department
</syntaxhighlight>
</syntaxhighlight>
 
|}
----
<syntaxhighlight lang='mysql' run>
<syntaxhighlight lang='mysql' run>
SELECT *
SELECT * FROM employee RIGHT JOIN department
FROM employee  
ON employee.DepartmentID = department.DepartmentID
RIGHT JOIN department ON employee.DepartmentID = department.DepartmentID
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='mysql' run>
<syntaxhighlight lang='mysql' run>
35번째 줄: 36번째 줄:
FROM employee A RIGHT JOIN department B
FROM employee A RIGHT JOIN department B
ON A.DepartmentID = B.DepartmentID
ON A.DepartmentID = B.DepartmentID
</syntaxhighlight>
==예시 2==
[[파일:right-outer-join-operation.png]]
<syntaxhighlight lang='mysql' run>
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
(3, 'Panama');
SELECT Sales.*, Countries.Country
FROM Sales RIGHT JOIN Countries
ON Sales.CountryID = Countries.ID
</syntaxhighlight>
</syntaxhighlight>


49번째 줄: 70번째 줄:
* {{영어위키백과||Join (SQL)#Right outer join}}
* {{영어위키백과||Join (SQL)#Right outer join}}


[[분류: JOIN]]
[[분류:조인]]

2021년 7월 26일 (월) 14:19 기준 최신판

1 개요[ | ]

SQL right join, right outer join
SQL 오른쪽 조인, 오른쪽 외부 조인, 오른쪽 조인, 라이트 조인, 라이트 아우터 조인

SQL Join - 03 A Right Join B.svg

SELECT *
FROM 테이블1 RIGHT JOIN 테이블2
ON 테이블1.컬럼=테이블2.컬럼;
SELECT *
FROM 테이블1 RIGHT OUTER JOIN 테이블2
ON 테이블1.컬럼=테이블2.컬럼;

2 예시 1[ | ]

SELECT * FROM employee
SELECT * FROM department
SELECT * FROM employee RIGHT JOIN department
ON employee.DepartmentID = department.DepartmentID
SELECT A.LastName, B.DepartmentID, B.DepartmentName 
FROM employee A RIGHT JOIN department B
ON A.DepartmentID = B.DepartmentID

3 예시 2[ | ]

Right-outer-join-operation.png

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
	(3, 'Panama');

SELECT Sales.*, Countries.Country
FROM Sales RIGHT JOIN Countries
ON Sales.CountryID = Countries.ID

4 같이 보기[ | ]

5 참고[ | ]

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