W3schools - SQL_JOIN
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
JOIN
Is used to combine rows from two or more tables, based on a related column between them
(INNER) JOIN : Returns records that have matching values in both tables
LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table
RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the table left table
FULL (OUTER) JOIN : Returns all records when there is a match in either left or right table
INNER JOIN
Selects records that have matching values in both tables
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
LEFT JOIN
Returns all records from the left table (table1), and the matching records from the right table(table2)
The result is 0 records from the right side, if there is no match
In some databases LEFT JOIN is called LEFT OUTER JOIN
SELECT colum_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
-- vice versa
FULL JOIN
Returns all matching records from both tables whether the other table matches or not
Can potentially return very large result-sets
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table.column_name = table2.column_name
WHERE condition;
-- FULL OUTER JOIN and FULL JOIN are the same
Self JOIN
Is a regular join, but the table is joined with itself
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;