Introduction
SQL Join is one of the most used query operations when working with complex and large applications containing several tables. Where you have to fetch data from many tables and apply many conditions. In those situations joins will play a major role. In this blog we will look into simple join operation for easy understanding.
SQL Joins
JOINS in SQL are used to combine tables in general. But there are different types of joins available in SQL. They are,
- Simple join / Inner join
- Left outer join
- Right outer join
- Full outer join
Syntax for Inner/Simple join
SELECT TABLE_1.column_1,TABLE_1.column_2,TABLE_2.column_1,....
FROM TABLE_1
INNER JOIN TABLE_2
ON TABLE_1.column_1= TABLE_2.column_2;
This is just for demonstration purpose, here the conditions can be from different column names. The condition is to match the values from the column on the left to the column on the right. In such way we give conditions "ON" Table_1.Column_1 = Table_2.Column_1;
Syntax for Multi-Join (Combining 3 tables)
select T1.COLUMN_1, T2.COLUMN_1, T3.COLUMN_1
from TABLE_1 T1
join TABLE_2 T2
on T1.COLUMN_1= T2.COLUMN_1
join TABLE_3 T3
on T2.CLOUMN_2 = T3.COLUMN_2
Eg:
TABLE-1
TABLE-2
TABLE-3
In above 3 tables we have "Country" names as common, so we can use them to perform join operations. We need to specify those in conditions using where or on conditions depending on our requirement.
Summary
We have seen the simple join operation syntax along with its purpose. I hope you will have clear understanding about join operation after viewing this blog containing very simple definition and syntax in easy manner. Thank you for reading.