1. Outer Join
These are three types.
- Left outer Join
- Right Outer Join
- Full Outer Join
2. Inner Join
These are two types.
Left Outer Join
In this there are two tables. We use a Left Outer Join operator on table A and table B and it takes all records of the left table (table A) and the matching values from the right table (table B). When there is not a matching value for a row then the Null value is used in each column.
Syntax
SELECT *
FROM Table A
LEFT OUTER JOIN Table B ON (condition );
Example
Before joining we have two tables, Employee and Department table.
Employee Table
Department Table
Right Outer Join
This join returns all the rows from the right table and that match from the left table. If there are no matching values in the left table NULL values are returned for each column. It is the reverse of the Left Outer Join.
Syntax
SELECT *
FROM Table A
RIGHT OUTER JOIN Table B ON (condition ) ;
Full Outer Join
This join combines the left outer join and right outer join. In this concept the Full Outer Join joins both tables. Then the resultant table contains a null value for every column of the table that lacks the matching row.
Syntax
SELECT *
FROM Table A
FULL OUTER JOIN Table B ON (condition ) ;
Inner Join
In the concept of Inner join we take the two tables Table A and Table B. First it finds all possible pairs between table A and table B. Matching rows between the two tables specified in the INNER JOIN statement based on one or more columns having matching data. The join that displays only the rows that have a match in both the joined tables is known as an inner join. For this, it finds the Cartesian product of these table. Then it implements the given condition on it. Find the desired output or result.
Syntax
SELECT *
FROM Table A
inner JOIN Table B ON (condition ) ;
Resources