SQL Joins are used to read data from two or more tables. SQL joins use common fields between tables to read data from two or more tables at the same time.
Consider we have two tables items and orders. We want to see all the items that have been order. To do this we will need to use SQL Join. SQL Join will connect these two tables and show them togather.
SELECT * FROM table1, table2
WHERE table1.column = table2.column
SELECT * FROM customers , orders
WHERE customers.CID = orders.CID
To join two or more tables using SQL, We need one or more columns that are available on all the joining tables. For example, we have two tables, customers, orders. We can use SELECT command to show customers and users. But we want to see All the orders with the customers names. Here we will need to join customers and orders tables
Types of SQL Join
There are two main types of SQL joins
- Inner Join
- Outer Join
Outer Join is further divided into two categories.
- Right Join
- Left Join