SQL Joins

In SQL, JOIN is a clause that is used to combine two or more tables over one or more columns.
Generally, there are 4 types of JOINS in SQL

  1. Left join
  2. Right join
  3. inner join
  4. full join
Whenever you google for SQL Joins, the first image you get from google will be this

That could be your cheat sheet. You can make use of it.

Left Join

Left join returns the content from the left table alone.
That's basically this one

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;





RightJoin

Right join returns the content from the right table alone.

SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;







Inner Join

Inner join returns values that are common from both table

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;






Full Join

Full join/ Full outer join returns values from both the table

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
Powered by Blogger.