MySQL JOINS

In MySQL there is 4 types of joins.
1. INNER JOINS
2. LEFT JOIN
3. RIGHT JOINS
4. FULL JOINS

1. INNER JOINS:
Returns result set when there is at least one match in both table.

Structure:
SELECT COLUMNS FROM TABLE_ONE
INNER JOIN TABLE_TWO
ON
TABLE_ONE.COLUMN_ONE = TABLE_TWO.COLUMN_ONE

2. LEFT JOIN:
Statement returns all results set from left table, even if match not found in right table. It is also called LEFT OUTER JOIN.

Structure:
SELECT COLUMNS FROM TABLE_1
LEFT JOIN TABLE_2
ON
TABLE_1.FIELD_NAME = TABLE_2.FIELD_NAME

3. RIGHT JOIN:
Statement returns all results set from right table, even if match not found in left table. It is also called RIGHT OUTER JOIN.

Structure:
SELECT COLUMNS FROM TABLE_1
RIGHT JOIN TABLE_2
ON
TABLE_1.FIELD_NAME = TABLE_2.FIELD_NAME

4. FULL JOIN:
Statement returns all results set if a match found in any table.

Structure:
SELECT COLUMNS FROM TABLE_1
FULL JOIN TABLE_2
ON
TABLE_1.FIELD_NAME = TABLE_2.FIELD_NAME

Posted in MySQL | Tagged , , , | Comments Off

Comments are closed.