How to Join two or more than two Tables using multiple columns | How to Join Multiple Tables
Вставка
- Опубліковано 30 січ 2022
- SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a related column between them.
Different Types of SQL JOINs
(INNER) JOIN: Returns records that have matching values in both tables
LEFT (OUTER) JOIN: Returns all records from the left table,
and the matched records from the right table,
The LEFT JOIN keyword returns all records from the left table (table1),
and the matched records from the right table (table2).
The result is NULL from the right side, if there is no match.
RIGHT (OUTER) JOIN: Returns all records from the right table,
and the matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table,
The FULL OUTER JOIN keyword returns all records when there is a match in left (table1)
or right (table2) table records.
Note: FULL OUTER JOIN can potentially return very large result-sets!
Tip: FULL OUTER JOIN and FULL JOIN are the same.
You can follow us on the below social media handles:-
Blog: - thedatamillennials.blogspot.com/
Facebook:- / the-data-millennials-5...
Instagram: - / the_data_millennials
LinkedIn: - / data-millennials-6b5a0...
Twitter: - / datamillennials
OMG you are a god !!! I have been looking at minimum 10 videos and yours are the most CLEARLY illustrated ONE !! Thanks a lot
@N Sangchat,
Hope you are well and I am Glad that our video was helpful .
Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
OMG you are a god !!! I have been looking at minimum 10 videos and yours are the most CLEARLY illustrated ONE !! Thanks a lot
Hi @Tejas Kumar.
I am Glad that our video was useful and helpful for you .
Request you to please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics.
And happy new year in Advance.
Explanations are so clear.
Thanks a bunch, I understand it clearly now. Please make a video for full outer join
Hi Glory,
I am Glad that our video is helpful . and i believe outer join explanation is uploaded in the sql playlist
Request you to please help us to reach out to all of those people who might want to learn something by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
*In case if you are struggling with any topic, Please connect with us on the given email id and we can connect over a quick google meet call and help you to resolve it.
Great tutorial. Thank you for your help!
HI @roi_4_dayz
I am Glad that our video was useful and helpful .
Request you to please check out our other videos of Excel, SQL and Google data studio ( Looker) and also please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
Fantastic fantastic you explained this so clearly please continue dropping videos. I am subscribing
Hi Alex,
I am Glad that our video was helpful and you have subscribed our channel.
*Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.*
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
Extremely helpful
apologies for the delayed response.
I am Glad that our video was useful and helpful .
Request you to please check out our other videos of Excel, SQL and Google data studio ( Looker) and also please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
This is perfect ❣️
Hi Dilip,
I am Glad that our video was helpful .
Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.
*And Request you to please subscribe our channel to learn more about such topics*
Well explained.
HI @Neha Jha,
I am Glad that our video was useful and helpful .
Request you to please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
Thank You Sir. Concept is very well explained.
HI @Abhishek Mahapatra,
I am really Glad that our video was useful and helpful for you.
Request you to please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
Outstanding explanation 😃
apologies for the delayed response.
I am Glad that our video was useful and helpful .
Request you to please check out our other videos of Excel, SQL and Google data studio ( Looker) and also please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
@@thedatamillennials acknowledged 🥰
thanks
great video sir😍😍😍
Hi @subhadip modak,
I am Glad that our video was helpful .
Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
@@thedatamillennials obviously sir, i suggest this channel who are wants to something new & advance topic.
@@subhadipmodak1321 thank you , we would really appreciate your help.🙏
I noticed that all the 3 tables had the same key "roll_no", so it's somehow easy. However, what happens for example when table 1 and 2 has a common key, and table 2 and 3 have a different key, how to relate table 1 and 3 in this case?
In that case you have to get the output by joining table 1 and table 2( lets say output 1 ) and then you have to get output by joining table 2 and table 3 ( lets say output 2) and then you can relate output 1 and output 2 using the common key .
you question is quite good and i think i should create a video on this question.
i will upload a video on your question and share the link here in the comment.
Great
apologies for the delayed response.
I am Glad that our video was useful and helpful .
Request you to please check out our other videos of Excel, SQL and Google data studio ( Looker) and also please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
why to use left join twice cannot we get the answer only with second left join
i have used two joins to give a taste that how you can join two or more than two table at once
One Question
If i need to print the name and percentage that they got from the same data how we can write the query for the same???
Please reply fast i am very curious
HI @To Lo Hasso,
Apologies for delayed response.
Below is the query which you have asked.
#use youtube_example;
select final.name, final.class, sum(final.Marks) as total_marks,
concat(round(((sum(final.Marks)/500)*100),0),"%") as student_percentage
from
(
select sd.Roll_No,
sd.class,
sd.name,
scd.Course_name,
smd.Marks
from student_data as sd
left join Student_Course_Data as scd on sd.Roll_No=scd.Roll_No
left join student_marks_data as smd
on(sd.roll_no=smd.Roll_No and scd.Course_name=smd.Course_name)
) as final
group by 1,2
;
@To Lo hasso,
Request you to please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
If you change a record or some data in one table does it change in all the tables that reference it?
no , it only changes the specific data that you have change.In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
good day . i have an issue with my leads platform . when i enter a lead it says it already exists . i wa looking into this issue and found that it maybe an issue with a DUPLICATE KEY . does anyone have any idea .
you have the issue with primary key, let me know if you are still facing the issue
We can use distinct keywords for marks
yes you can use
hi, i have question,
if we are using left join
from student_data as sd
left join Student_Course_Data as scd
so the table on the left is sd ,
let say we add left join student_marks_data as smd
on scd.Roll_No=smd.Roll_No
are we consider table scd as left table for joining or still sd?
HI Farah, The first table which you have used in From clause (in this case student data as sd ) will always be the let table..
Hope the above explanation clears your confusion.
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
Understood that,sure i will spread your video with my colleague
@@farahamirah2091 Thanks. We would really appreciate your help.
Sir can we use where condition in left join
HI Pradeep,
Yes you can use where condition in Left join.
after joining the table you can use the where clause on left table's Column.
For example suppose you have 2 table -- table 1 and table 2 and your table table1 is your left table then you can use the where condition like this
Select t1.col1,t1.col2,t2.col3
from table 1 as t1
left join table2 as t2
where t1.col1="condition".
In case if you are struggling with any topic, Please connect with us on the below given email id and we can connect over a quick google meet call and help you to resolve it.
Email Id:- master.datamillennials@gmail.com
Request you to please help us to reach out to all of those people who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics
@@thedatamillennials i can't understand sir
@@pradeepravi9608 Lets connect over google meet and will clear your confusion .
You can send google meet link or invite on the below email master.datamillennials@gmail.com
Hi, can you tell why we went for left join for both joins?
Hi @Deepthi,
We went for left join for both the table , because as per our requirement we required all the rows from both of the tables
Could you please share with us excel sheet for practicing?
Please drop me a note on below email id and I will share the data with over the email
master.datamillennials@gmail.com
hello please what is 'sd ' and ' 'scd'
hi sd and scd is the alias name of the table that i had given while joining the tables.
Can someone pls explain what query we can use in this to get the final o/p
Source A
ID Name State
1 A Delhi
2 B Delhi
3 C
Source B
ID Name State
1 A Delhi
3 C Haryana
4 D Mumbai
5 E
Final Output:
ID Name State
1 A Delhi
2 B Delhi
3 C Haryana
4 D Mumbai
5 E Null
Hi @Neha Roy
There are multiple ways to solve this kind of problem statement.
But one of the easiest way is to use full join.
The Full Join basically returns all records from the left table and also from the right table. For example, let’s say, we have two tables, Table A and Table B. When Full Join is applied on these two tables, it returns us all records from both Table A and Table B. If the condition is not met, then the null value is displayed instead
Please let me know, if you want me to create a video on your problem statement
content is blurred
ok , will try to make videos in high definition
can you share this video insert query?
Hi @Sahil Rohilla,
Apologies for delayed response.
As requested in the comment, please find the below query used in this video.
select sd.Roll_No,
sd.class,
scd.Course_name,
smd.Marks
from student_data as sd
left join student_Course_Data as scd on sd.Roll_No=scd.Roll_No
left join student_marks_data as smd
on (sd.Roll_No=smd.Roll_No and scd.Course_name=smd.course_name)
And Request you to please subscribe our channel to learn more about such topics
Aise to koi paise le k bhi ni samjhata !! 🫀
I am Glad that our video was useful and helpful .
Request you to please check out our other videos of Excel, SQL and Google data studio ( Looker) and also please help us to reach out to all your friends and family members who might want to learn something new by sharing our content.
And Request you to please subscribe our channel to learn more about such topics