SQL Join


A SQL join is used to retrieve data from two or more tables in a database.
 
SQL Join

Syntax :-  

SELECT column_names
FROM table_name1 JOIN table_name2
WHERE condition;

Example : figure in below, we have, two tables customers and orders. 


Now, let see join these two tables in our SELECT statement as shown below.

Query :

SELECT ID, Name, Address

FROM customers JOIN orders

WHERE customers.ID = orders.customers_Id;


Output : 


Types of SQL Joins

  • Inner Join :- Returns the records by matching the values of both the given tables.

             

  • Left Join :- Returns all records in the Left table by matching the Right table.

  • Right Join :- Returns all records in the Right table by matching the Left table.


  • Full Join :-  Returns all records when there is a match in left or right table.