 Hello guys, welcome back. My name is Susheel Singh and this is continuation of SQL Server interview questions and answers. In this session, you will understand how joints work and second is team matches. So team matches is our interview question. So directly move to our question. So you can see we have input table and it contains two columns. First is ID, second is team. So ID has four rows and team also. So in team you can see India, Australia Sri Lanka and Pakistan. So in output we want only one column and here so in our input table teams will play with other teams like India will play with Australia, Sri Lanka and Pakistan and then again Australia will play with India, Sri Lanka and Pakistan. So in our output each team will play with other teams like India will play with Australia. So this is our first row. India will play with Sri Lanka. So this is our second row. India will play with Pakistan. So this is our third row. So now Australia we can see Australia has played with India. So this row will be skipped and then Australia will play with Sri Lanka. So this is our fourth row. Australia will play with Pakistan. So this is our fifth row. Now Sri Lanka will play with Pakistan only because Sri Lanka has played with Australia and India so when slanka will play with Pakistan for our last row and then we can see Pakistan has played with India Australia and slanka so we can see each teams has played with other teams so this is our input input table and we want this output so how we can achieve this so first we need to understand how joints work so here you can see we have a input table and we are going to use as a self-join so we split this table into two parts for T1 and T2 so T1 our left table so T our left table and T1 is our right table so when we are going to join between them it will pick the first row from left table and it join from right table one by one so ID team ID one will join with T1 team ID one so condition will not be satisfied then this row will be skipped and then move to our second row so second row we can see ID is one and then ID is two so we can see here T ID and T1 ID so value of T ID is one and value of T1 ID is two so in our output we can see it will reflect India and then versus T1 name is Australia so it will reflect this output and then again team ID one will check with slanka so our condition will satisfy so T1 name it India and then versus and then we can see slanka and next ID is one and ID T1 ID for Pakistan is four so our condition will satisfy then we can see India and then versus Pakistan so our condition will satisfy for all these row once this value will be completed then it will move to our second row and it will try again check from starting to end and join between them so two will check from one so condition will not be satisfied then it will move to our second condition will not be satisfied for the row number three ID is three is greater than ID is two so it will reflect Australia for our left table and then versus then slanka from our right table for Pakistan condition will satisfy then Australia and then versus then Pakistan so for the our third row only this condition will satisfy slanka and Pakistan so we can see slanka versus Pakistan so this is our output and we want this output as we can see here so this is our output and we can get this output by using self-join in this input table and we are going to put condition between team ID when team ID from left table is less than team ID from right table so let's move to sequence row management to studio I have already created this table we can select this table we can see here we have two rows one two three four and then India Australia slanka and Pakistan we are going to put inner join between them and we can see in excel we are going to join between T and T1 by using team ID when team ID from left table is less than team ID from right table we did the same thing here we on condition and then T team ID is less than T1 team ID so let's execute this query and we can see we are getting the same output as we can see in excel so copy and paste here and here you can see India versus Australia India versus Australia India versus slanka India versus slanka and then India versus Pakistan India versus Pakistan Australia versus slanka Australia versus slanka and all these rows are same so we can achieve this output by using this query I hope you have understand this video and thank you so much for watching this video if you like this video please subscribe our channel for many more videos if you want this script these will be available on my Facebook page you can copy from there thank you so much