Hello Everyone,
In this post, we will discuss on SQL joins with a clear understanding of how it works and when to use joins. It does not meter how much experience you have in database field, it will help to get the data from different tables.
SQL joins are used to combine rows of more than one tables based on foreign and primary keys. It allows us to retrieve data from multiple tables in a single query from our databases.
Types of SQL Joins
- Inner Join.
It will return only those rows that have matching values in both tables. - Left Join.
It will return all rows from the left table and matching rows from the right table. - Right Join.
It will return all rows from the right table and matching rows from the left table.
These are the most important and common joins. there are more joins like self-join and cross join but mostly these three types of joins are used mostly. Joins play a crucial role in the report and data development. it is not meter which data base that you are using.
No | sector | cust_id | name_1 |
---|---|---|---|
1 | 1000 | 4270603 | SIKANDAR |
2 | 1000 | 4270939 | ALI TARIQ |
3 | 1000 | 5715170 | ALI HAMZA |
4 | 1000 | 7796882 | IMRAN |
5 | 1000 | 953045 | UMAR |
No | sector | cust_id | Town |
---|---|---|---|
1 | 1000 | 4270603 | PESHAWAR |
2 | 1000 | 4270939 | ALI PUR |
3 | 1000 | 5715170 | GALA YOUSAF |
4 | 1000 | 7796882 | KHANEWAL |
5 | 1000 | 953045 | YAZMAN |
there are two tables, in one table name_1 exist and in second table town exist. i want to get the both name_1 and town. then join will use. the below is the syntax of joins.
SELECT
u1.No , u1.sector , u1.cust_id , u1.name_1 , u2.Town,
FROM user1 as u1
INNER JOIN user2 as u2
ON u1.cust_id= u2.cust_id;
No | sector | cust_id | name_1 | Town |
---|---|---|---|---|
1 | 1000 | 4270603 | SIKANDAR | PESHAWAR |
2 | 1000 | 4270939 | ALI TARIQ | ALI PUR |
3 | 1000 | 5715170 | ALI HAMZA | GALA YOUSAF |
4 | 1000 | 7796882 | IMRAN | KHANEWAL |
5 | 1000 | 953045 | UMAR | YAZMAN |
I hope, things will clear with above picture. you can see that in inner join only matching data will retrieve. we can use more than one join in a query to get the result of data. It would be my pleasure if you will share your opinion and reviews on this topic.
Please cast witness vote to @bangla.Witness or set proxy to @rme.
_
Vote @bangla.witness as witness
Set Proxy @rme as proxy
Special Thanks.
Cc: @rme
Cc: @hungry-griffin
Cc: @steemcurator02
Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram
🆃🅷🅰️🅽🅺 🆈🅾️🆄