Learn how to use SQL JOIN clause to combine the two tables and fetch record from those tables. Combine rows of two tables using the JOIN clause based on the same column on both the tables.
The common fields between the two tables can be used to perform the JOIN operation. You have to use the JOIN clause to access one or more table and fetch the data using the SQL SELECT statement.
There are five types of SQL JOIN given below in the list.
- Inner Join
- Left Outer Join
- Right Outer Join
- Full Outer Join
- Cross Join
You can learn about them in later tutorials given in the next pages with the examples and explanations. If you want to understand the JOIN clause with examples, keep reading this page tutorial.
How to Use SQL JOIN to Combine Two Tables
Suppose there are two tables, one for Purchaser and other for the Seller. Below are the tables you have to use to combine using the SQL JOIN clause.
Table Name: Purchaser
Purchaser_ID | Purchaser_Name | Plot_No | Service_Id |
---|---|---|---|
1 | Bill | 26 | 10001 |
2 | Nick | 27 | 10002 |
3 | Loony | 28 | 10003 |
4 | Monk | 29 | 10004 |
The above table contains the 4 columns with 4 rows of data.
Another table is for the Seller given below. It contains the Id field as the first column name. This column contains the id match with Purchase table Service_Id column.
Id | Seller_Name | Seller_Email |
---|---|---|
10001 | Rock | [email protected] |
10002 | Sanky | [email protected] |
10003 | Kurt | [email protected] |
To combine the above two tables, you have to use the common column called Service_Id between them. The example of the statement which you have to write to combine above two tables
1 2 3 |
SELECT Service_Id, Seller_Name, Purchaser_Name, Plot_No FROM Purchaser p, Seller s WHERE p.Service_Id = s.Id |
Output
Service_Id | Seller_Name | Purchaser_Name | Plot_No |
---|---|---|---|
10001 | Rock | Bill | 26 |
10002 | Sanky | Nick | 27 |
10003 | Kurt | Loony | 28 |
The above output contains the columns which you have made combined using the JOIN clause. In the next chapters, you will learn details of all the types of JOIN.
Reference