 Hello, welcome to SSUnitech. So, sale this site and this is continuation of sequence over interview questions and answers. So, today we gonna discuss about one more interview question that is how to write a query to get those employees who has salary greater than their manager. Have a look of table in next slide. So, as we can see we have input table that contains four columns. First is employee ID, then employee name, employee salary and manager ID. So, we are having total four columns and in our output we are also having four columns those are present in our input. But as we can see for Naveen, so his manager is Mukesh and Naveen's salary is 1 lakh and Mukesh's salary is 30,000. So, 1 lakh is greater than 30,000. So, Naveen will move to our output. Next for employee ID 5, employee is Joanne and Joanne's salary is 1,70,000 and her manager is Howard. So, Howard's salary is 1 lakh, 68,000. So, Joanne's salary is more than Howard. So, Joanne's record will move to our output. How we can write the query to get this output? Go to on SQL Server Management Studio and here as we can see I have already written this script to create the table and insert a record on it. So, we can execute this as we can see six rows affected. Now, we can check the data. We can write select statement, select a stick from our table. Now, we can execute and we can check. So, this metadata and our slides metadata both are same. Now, we can copy this record and go to on Excel to understand about the logic, how we can implement the logic. So, we are going to use self-drain. So, let me paste this result set two times and let's call it as employee and second as manager. First, we want to match with ID from employee table and then from manager table with major ID. So, this is our first join condition. In our second join condition, we will check salary for the employee and salary for the manager. If employee's salary is more than manager's salary, then we will put into our output. So, as we can see in our first room employee ID is 1 and manager is 2. So, it will match with our second record and here as we can see employee's salary is 1 lakh and manager's salary is 30000. So, first record will move to our output. So, it will be our output. In case of join, as we can see her manager's ID is 6. So, that is our Harvard. So, it will match with Harvard and here it will check for employee's salary that is 1 lakh 70,000 and manager's salary is 1 lakh 68,000. So, this record will move to our output. So, go to on sequence of management studio. So, go to on sequence of management studio to write the query. As I am using SQL 2K17, you may have another version of SQL server, but query would be same for all the versions. So, here this is our employee table as we have discussed. Then we need to put an inner join. So, this is our inner join and then this is for manager. In our on condition, first we need to check for the employee's manager ID. So, manager ID then it should match with manager's.id. That is fine. Next condition would be employee's salary. So, employee's salary that is our EMP cell should be greater than manager's salary. So, m dot EMP salary. We want to get data from employee table only. So, we can put employee dot star now. So, let me execute this query. So, as we can see we are getting ID1 and ID5. In our slide as we can see employee ID5 and employee ID1 we are having. So, I hope you have understand how we can write the query to get those employees who has greater salary than their managers. And thank you so much for watching this video. If you need this script it will be a label or description of this video you can copy from there. Thank you so much for watching and do subscribe our channel and press the bell icon to get the notification of our newly uploaded videos. Thank you so much.