Very Famous SQL Interview Question | Department Highest Salary

  ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 23,643

Sumit Mittal

Sumit Mittal

2 ะถั‹ะป ะฑาฑั€ั‹ะฝ

๐–๐š๐ง๐ญ ๐ญ๐จ ๐Œ๐š๐ฌ๐ญ๐ž๐ซ ๐’๐๐‹? ๐‹๐ž๐š๐ซ๐ง ๐’๐๐‹ ๐ญ๐ก๐ž ๐ซ๐ข๐ ๐ก๐ญ ๐ฐ๐š๐ฒ ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐ญ๐ก๐ž ๐ฆ๐จ๐ฌ๐ญ ๐ฌ๐จ๐ฎ๐ ๐ก๐ญ ๐š๐Ÿ๐ญ๐ž๐ซ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž - ๐’๐๐‹ ๐‚๐ก๐š๐ฆ๐ฉ๐ข๐จ๐ง๐ฌ ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ!
"๐€ 8 ๐ฐ๐ž๐ž๐ค ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐๐ž๐ฌ๐ข๐ ๐ง๐ž๐ ๐ญ๐จ ๐ก๐ž๐ฅ๐ฉ ๐ฒ๐จ๐ฎ ๐œ๐ซ๐š๐œ๐ค ๐ญ๐ก๐ž ๐ข๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ๐ฌ ๐จ๐Ÿ ๐ญ๐จ๐ฉ ๐ฉ๐ซ๐จ๐๐ฎ๐œ๐ญ ๐›๐š๐ฌ๐ž๐ ๐œ๐จ๐ฆ๐ฉ๐š๐ง๐ข๐ž๐ฌ ๐›๐ฒ ๐๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ข๐ง๐  ๐š ๐ญ๐ก๐จ๐ฎ๐ ๐ก๐ญ ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐š๐ง๐ ๐š๐ง ๐š๐ฉ๐ฉ๐ซ๐จ๐š๐œ๐ก ๐ญ๐จ ๐ฌ๐จ๐ฅ๐ฏ๐ž ๐š๐ง ๐ฎ๐ง๐ฌ๐ž๐ž๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ."
๐‡๐ž๐ซ๐ž ๐ข๐ฌ ๐ก๐จ๐ฐ ๐ฒ๐จ๐ฎ ๐œ๐š๐ง ๐ซ๐ž๐ ๐ข๐ฌ๐ญ๐ž๐ซ ๐Ÿ๐จ๐ซ ๐ญ๐ก๐ž ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ -
๐‘๐ž๐ ๐ข๐ฌ๐ญ๐ซ๐š๐ญ๐ข๐จ๐ง ๐‹๐ข๐ง๐ค (๐‚๐จ๐ฎ๐ซ๐ฌ๐ž ๐€๐œ๐œ๐ž๐ฌ๐ฌ ๐Ÿ๐ซ๐จ๐ฆ ๐ˆ๐ง๐๐ข๐š) : rzp.io/l/SQLINR
๐‘๐ž๐ ๐ข๐ฌ๐ญ๐ซ๐š๐ญ๐ข๐จ๐ง ๐‹๐ข๐ง๐ค (๐‚๐จ๐ฎ๐ซ๐ฌ๐ž ๐€๐œ๐œ๐ž๐ฌ๐ฌ ๐Ÿ๐ซ๐จ๐ฆ ๐จ๐ฎ๐ญ๐ฌ๐ข๐๐ž ๐ˆ๐ง๐๐ข๐š) : rzp.io/l/SQLUSD
๐–๐š๐ง๐ญ ๐ญ๐จ ๐ฅ๐ž๐š๐ซ๐ง ๐๐ข๐  ๐ƒ๐š๐ญ๐š ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ?
๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ ๐ญ๐ก๐ž ๐›๐ข๐  ๐๐š๐ญ๐š ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž ๐๐ž๐ญ๐š๐ข๐ฅ๐ฌ
๐–๐ž๐›๐ฌ๐ข๐ญ๐ž : trendytech.in/?src=youtube&su...
I have trained over 20,000+ professionals in the field of Data Engineering in the last 5 years.
Very Famous SQL Interview Question | Department Highest Salary
In this video we will solve Problem number 184 on LeetCode
Department Highest Salary
This is a medium complexity SQL Interview Question
Do Like, Comment & Subscribe ..
๐—๐—ผ๐—ถ๐—ป ๐—บ๐—ฒ ๐—ผ๐—ป ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ:๐Ÿ”ฅ
๐Ÿ”…Sumit LinkedIn - / bigdatabysumit
๐Ÿ”…Sumit Instagram - / bigdatabysumit
In this video, we will solve SQL question on LeetCode. LeetCode is an excellent platform for practicing SQL Queries. The SQL Questions on LeetCode are framed pretty similar to how they are asked on SQL Interviews hence solving SQL questions on LeetCode can give you a good hands on experience on solving real world SQL questions.
#sql #interview #leetcode

ะŸั–ะบั–ั€ะปะตั€: 35
@sumitmittal07
@sumitmittal07 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
Checkout the Big Data course details here: trendytech.in/?referrer=youtube_lc5
@sonumahto1364
@sonumahto1364 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
select Department, Employee, Salary from ( select d.name as Department,e.name as Employee,e.salary, rank() over (partition by departmentid order by salary desc) rnk from Employee e join department d on e.departmentid=d.id ) x where x.rnk=1 It is more optimised
@himanchalchandra6202
@himanchalchandra6202 ะะน ะฑาฑั€ั‹ะฝ
use dense_rank over rank as it will allow more than 1 highest salary in each dept
@rokibhasan5184
@rokibhasan5184 4 ะฐะน ะฑาฑั€ั‹ะฝ
Finished the whole playlist. Really helpful. I've learned How to approach any SQL problem.
@sathiyanr3992
@sathiyanr3992 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
More Useful Sir. Kindly upload these kinds of problems continuously.
@subhajitroy5850
@subhajitroy5850 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Please bring few more problem statements showing the usage of full outer join & Cartesian product as well
@arunsundar3739
@arunsundar3739 3 ะฐะน ะฑาฑั€ั‹ะฝ
'where' clause with more than one column, along with 'in' clause is a combination i am learning first time, very interesting, gaining more confidence in sql questions now :)
@RITURAJRANJAN-st7dv
@RITURAJRANJAN-st7dv 2 ะฐะน ะฑาฑั€ั‹ะฝ
Thanks for the wonderful solution Sir. I have tried to solve in a different way. select Department,Employee,salary from (select Department,Employee,salary,dense_rank() over(partition by Department order by salary desc) as denserank from (select e.name as Employee,salary,d.name as Department from Employee e join Department d on e.departmentId = d.id) temp) temp1 where denserank=1;
@angelnadar6451
@angelnadar6451 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Thanks @ helpful !!!
@sumitmittal07
@sumitmittal07 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Glad that it was helpfull
@florincopaci6821
@florincopaci6821 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Thank you for all the videos! can you please please do a video about leetcode sql question 2153-number of passengers in each bus 2?Please.Thank you
@venkataram6460
@venkataram6460 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Please upload more videos to this playlist
@ashitosh501
@ashitosh501 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
sir waiting for next session
@sumitmittal07
@sumitmittal07 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Very soon
@faizraina9917
@faizraina9917 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
why are we using department id in sub-query . why do we need to include it , can't we just use max(salary) only
@razeenahmed7334
@razeenahmed7334 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
No, we can't use only max(salary) in the sub-query, because that will return only one maximum salary, but here we want to retrieve max salaries for both of the departments!
@dikshagupta2795
@dikshagupta2795 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Hello Sir, If we are using sql server then what will be the alternative for "WHERE (departmentId, salary)" as we can't use two columns in WHERE in sql server
@AnweshDash
@AnweshDash 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
use window functions
@103himajapoluri6
@103himajapoluri6 ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
Can anybody help with identifying what is wrong in this query select d.name as Department,e1.name as Empolyee ,max(salary) as Salary from employee e1,department d where e1.departmentId = d.id group by d.name ;
@ShivaKumar-dj8bj
@ShivaKumar-dj8bj ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
This will not work because here in each department for each employee there will be only one row for salary...your query gives result department, employee name and the highest salary of him, here there is only one row so basically no aggregation will happen considering there is only one row for each employee in each department. the logic is you need to first partition the data department wise then order the data by salary in descending order for each department and get the first row in each partitioned data set. you can use either Row number or dense rank to achieve this....check once.
@adnanmulla6640
@adnanmulla6640 6 ะฐะน ะฑาฑั€ั‹ะฝ
Alternate way: select Department,Employee,Salary from (select d.name as Department, e.name as Employee, dense_rank() over (partition by d.name order by salary desc) as Sal, Salary from Employee e inner join Department d on e.departmentId=d.id)x where x.Sal=1
@lucifieramit1
@lucifieramit1 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
select temp.name as Department,temp.employeename as Employee ,temp.salary as Salary from (select d.name,e.name as employeename,salary,dense_rank() over ( partition by d.name order by salary desc ) as dr from employee e join department d on e.departmentId=d.id) temp where temp.dr=1
@thomsondcruz5456
@thomsondcruz5456 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Window functions are not always cost effective
@sukanyaiyer2671
@sukanyaiyer2671 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
pls solve prob 627
@sumitmittal07
@sumitmittal07 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Noted :) will cover that in the upcoming sessions
@sukanyaiyer2671
@sukanyaiyer2671 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
@@sumitmittal07 thank you sir
@lucifieramit1
@lucifieramit1 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
@@sukanyaiyer2671 you need to use update with case statement in that problem
@slyroy7562
@slyroy7562 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Select * from (Select employee.department, employee.name employee, salary, dense_rank() over(partition by employee.department order by salary desc) as r from employee, department where employee. Id = department. Id) where r=1; Will this works?
@sukanyaiyer2671
@sukanyaiyer2671 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Yes. It works
@dikshagupta2795
@dikshagupta2795 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
There are some changes I have made and after that the query gives expected results: select Department, Employee, Salary from ( Select Department.name as Department, employee.name as Employee, Salary, dense_rank() over(partition by employee.departmentId order by salary desc) as r from employee join Department on employee.departmentId = Department.id ) as r where r = 1
@slyroy7562
@slyroy7562 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
@@dikshagupta2795 Thanks
@karthikbs8457
@karthikbs8457 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
Sir I saw all the previous 5 video. This problem I paused and solved the problem on my own. Thanks. But I used Partition method involving 3 select statements. SELECT temp1.Department,temp1.name as Employee,temp1.Salary FROM( SELECT *, RANK() OVER(PARTITION by temp.departmentId ORDER BY temp.Salary DESC) AS rnk FROM( SELECT e.*,d.name as "Department" FROM Employee e INNER JOIN Department d ON e.departmentId=d.id) temp ) temp1 WHERE temp1.rnk=1;
@ShivaKumar-dj8bj
@ShivaKumar-dj8bj ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
for this highest salary rank will work but if you want to get nth highest salary you need to use dense rank...correct me if I'm wrong
@Foodie_Cooking_Loverz
@Foodie_Cooking_Loverz ะ–ั‹ะป ะฑาฑั€ั‹ะฝ
Looks complicated querry
@vishwamgupta1329
@vishwamgupta1329 2 ะถั‹ะป ะฑาฑั€ั‹ะฝ
WITH Solution as (SELECT Employee.name as Employee, Employee.salary as Sal ,Department.name as Department, DENSE_RANK() OVER(PARTITION BY Department.name ORDER BY Employee.salary DESC) as re FROM Employee INNER JOIN Department ON Employee.departmentID=Department.id) SELECT Department, Employee ,Sal as Salary FROM Solution WHERE re=1; #This one also worked using Dense rank window function
SQL Interview Question - Find Nth Highest Salary | LeetCode
30:40
Sumit Mittal
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 37 ะœ.
Difference between Database vs Data lake vs Warehouse
25:05
Sumit Mittal
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 34 ะœ.
ะญั‚ะพั‚ ะŸั‘ั ะšะพะต-ะงั‚ะพ ะะฐะดะตะปะฐะป ๐Ÿ˜ณ
00:31
ะ“ะปะตะฑ ะ ะฐะฝะดะฐะปะฐะนะฝะตะฝ
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 4,6 ะœะ›ะ
ะ‘ะžะ›ะฌะจะžะ™ ะŸะ•ะขะฃะจะžะš #shorts
00:21
ะŸะฐัˆะฐ ะžัะฐะดั‡ะธะน
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 10 ะœะ›ะ
ะšะะš ะ”ะฃะœะะ•ะขะ• ะšะขะž ะ’ะซะ™ะ“ะ ะะ•ะข๐Ÿ˜‚
00:29
ะœะฏะขะะะฏ ะคะะะขะ
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 6 ะœะ›ะ
Find Nth Highest Salary in SQL | 5 Different Ways | Most Important SQL Interview Question
12:13
CodeEra
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 97 ะœ.
Leetcode SQL Interview Questions  | Practise SQL questions
17:50
Sumit Mittal
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 21 ะœ.
Famous SQL Interview Question | First Name , Middle Name and Last Name of a Customer
14:07
Ankit Bansal
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 24 ะœ.
LeetCode Medium 184 "Department Highest Salary" Amazon Interview SQL Question With Explanation
7:21
Everyday Data Science
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 3,1 ะœ.
REAL SQL Interview PROBLEM by Capgemini | Solving SQL Queries
9:33
techTFQ
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 56 ะœ.
SQL Query | How to find employees with highest salary in a department
10:38
Learn at Knowstar
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 47 ะœ.
3 Very Important SQL Interview Questions on LeetCode | Practise SQL Questions
23:43
Sumit Mittal
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 35 ะœ.
Practice SQL Interview Query | Big 4 Interview Question
14:47
techTFQ
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 119 ะœ.
FULL SQL DATABASE COURSE | Learn SQL in 70 minutes
1:10:01
Mo Chen
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 131 ะœ.
The 25 SQL Questions You MUST Know for Data Analyst Interviews
32:47
KSR Datavizon
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 199 ะœ.
ะญั‚ะพั‚ ะŸั‘ั ะšะพะต-ะงั‚ะพ ะะฐะดะตะปะฐะป ๐Ÿ˜ณ
00:31
ะ“ะปะตะฑ ะ ะฐะฝะดะฐะปะฐะนะฝะตะฝ
ะ ะตั‚ า›ะฐั€ะฐะปะดั‹ 4,6 ะœะ›ะ