Join in SQL

Join in SQL is used to combine rows from two or more tables, based on a common field between them.

 

Join Keyword is used in SQL queries for joining two or more tables. The minimum required condition for joining table is at least one column should be common in joining tables.

 

Types of JOIN in SQL :

  • SQL Inner JOIN

  • SQL LEFT OUTER JOIN

  • SQL RIGHT OUTER JOIN

  • SQL FULL JOIN

 

SQL Inner Join

An inner join produces a result set that is limited to the rows where there is a match in both tables for what we’re looking for.

 SQL Inner Join

SQL Synatx :

SELECT columns FROM table1

INNER JOIN table2

ON table1.column = table2.column;

 

SQL Left Outer Join

A left outer join, or left join, results in a set where all of the rows from the first, or left-hand side, table are preserved. The rows from the second or right-hand side table only show up if they have a match with the rows from the first table.

 SQL Left Outer Join

SQL Synatx :

SELECT columns FROM table1

LEFT  JOIN table2

ON table1.column = table2.column;

 

SQL Right Outer Join

A right outer join, or right join, is the same as a left join, except the roles are reversed.  All of the rows from the right-hand side table show up in the result, but the rows from the table on the left are only there if they match the table on the right.

 SQL Right Outer Join

SQL Synatx :

SELECT columns FROM table1

RIGHT  JOIN table2

ON table1.column = table2.column;

 

SQL FULL Join

A full outer join, or just outer join, produces a result set with  all of the rows of both tables, regardless of whether there are any matches.

 SQL Full Outer Join

SQL Synatx :

SELECT columns FROM table1

FULL  JOIN table2

ON table1.column = table2.column;

 

0 Comment

Leave a Reply