Query To Find Nth Highest Salary In SQL | SQL Interview Question

  Рет қаралды 288,982

Crack Concepts

Crack Concepts

Күн бұрын

Пікірлер: 202
@Indian_mutualfund_expert
@Indian_mutualfund_expert 3 жыл бұрын
Hi Mam I regularly follow your videos... Mam in subquery at end of the brackets you need to mention any alphabet then only the query will get executed other wise it given error... Select top 1 sal from (select top 3 sal from emo order by sal desc) s order by sal asc...
@crackconcepts
@crackconcepts 3 жыл бұрын
Yes. You’re right
@danishdude6750
@danishdude6750 3 жыл бұрын
@@crackconcepts And you should do a select distinct top N salary in your inner select so you don't get duplicates if more people have the same salary.
@AsifIquebalSarkar
@AsifIquebalSarkar 3 жыл бұрын
rows can have same salary and we may need to fetch all of them, so WITH TIES would be a better option
@ashutoshanand4040
@ashutoshanand4040 3 жыл бұрын
YES I NOTICED THAT AS WELL BUT WHAT IS THE REASON?
@Somnath-je9nd
@Somnath-je9nd 3 жыл бұрын
why s outside that bracket ? can you explain
@akashlondhe1110
@akashlondhe1110 3 жыл бұрын
Instead of select top 1 from (subquery) order by sal desc .. you can write select min(sal) from (subquery)
@maheshtambe9535
@maheshtambe9535 3 жыл бұрын
Good one
@devprakash4671
@devprakash4671 3 жыл бұрын
Noice
@kishanmishra7383
@kishanmishra7383 3 жыл бұрын
@@chandrakanthotkar7262 Not necessary. It'll give the output
@karthikgolagani6844
@karthikgolagani6844 3 жыл бұрын
@@chandrakanthotkar7262 not needed
@crackconcepts
@crackconcepts 4 жыл бұрын
Hi, do check out the whole SQL Playlist for more such videos!
@anerishah679
@anerishah679 4 жыл бұрын
Really wonderful explanation!
@manimuttu1
@manimuttu1 4 жыл бұрын
Nice explanation!! and please add the playlist url as well :)
@bharatiyadav8333
@bharatiyadav8333 3 жыл бұрын
Other clean way is to use limit and offset : "Select sal from Emp Order By sal Desc Limit 1 Offset 2 ;" Limit X Offset Y : select X rows from (Y+1)th row
@user-pr9pq8en2d
@user-pr9pq8en2d 3 жыл бұрын
I had this in my mind..
@preexa5797
@preexa5797 3 жыл бұрын
Hn re limit use krne ka simple and easy
@sarikadatta3706
@sarikadatta3706 2 жыл бұрын
Thank you Bharati Yadav You made it so much easier. I tried your method and it worked. What she showed in video is logical but for some reason it gives me an error in mysql Thanks a ton for helping me out
@thehavoc6331
@thehavoc6331 2 жыл бұрын
Damn, this is so easy and in one line, but I don't understand how offset works😅 I understood until LIMIT 1 but how does "offset 2" give you the third highest salary Can anyone explain this to me?
@yogeshwarjoshi
@yogeshwarjoshi 3 жыл бұрын
I think you need a distinct for salary otherwise it will fail if few people have same salaries.
@aashishprashant2402
@aashishprashant2402 3 жыл бұрын
Select T.column_name, Dense_Rank() over (order by salary desc) as Rank from T_Tablename where Rank = N;
@universal4334
@universal4334 3 жыл бұрын
Geeks for geeks
@jv___6729
@jv___6729 3 жыл бұрын
;with rno as ( Select Id, salary , dense_rank() over (order by salary) as salarycte From emp ) Select Id, salary from rno where salarycte = 3
@Jyotisingh-qm4fm
@Jyotisingh-qm4fm 3 жыл бұрын
Hello aashis
@vivekkrishnan514
@vivekkrishnan514 3 жыл бұрын
Thanks a lot, you just changed my life. I had watched almost all the videos and attended the interview. I passed 1 written exam and 3 technical rounds and I got selected for the SQL Developer Job only because of you. Thanks a lot for the effort you made. Keep teaching us, videos are really informative and easily understandable. 😇🙏🏻😇
@crackconcepts
@crackconcepts 3 жыл бұрын
I’m so glad my videos helped you. Congratulations on the new job!
@danushhu1317
@danushhu1317 3 жыл бұрын
Shata 😂 dengda sariyagi
@ranaprathap8292
@ranaprathap8292 3 жыл бұрын
Bro any requirements for SQL pls reply me
@kushalgupta8353
@kushalgupta8353 3 жыл бұрын
Other Solution: select salary from (select salary from employee order by desc limit 3) order by salary asc limit 1;
@Jagadish12345
@Jagadish12345 3 жыл бұрын
it’s not a different solution, it’s just different database’s query like top works for mssql where as limit works for mysql and postgresql
@av98
@av98 3 жыл бұрын
@@Jagadish12345 you are right For Oracle it's FETCH
@thinkingmad1685
@thinkingmad1685 3 жыл бұрын
@@Jagadish12345 similar way can you tell for sql plus
@paramvirsohi5922
@paramvirsohi5922 3 жыл бұрын
The bestest and the easieST place ON ENTIRE INTERNET TO FIND ANSWER. TYSM. HELPED ME IN INTERVIEW
@pratikkulkarni4929
@pratikkulkarni4929 3 жыл бұрын
Absolutely super today this is asked in interview for me and today i got this answer
@saiteja5246
@saiteja5246 3 жыл бұрын
We can use select * from(select *,rank() over(order by sal desc) rno from emp)src where rno = Nth value
@GANESH-zi2xb
@GANESH-zi2xb 3 жыл бұрын
This query is wrong
@himanshugupta4807
@himanshugupta4807 3 жыл бұрын
In case of duplicate your query will not give expected result. We can use dense function instead rank function because rank give pit holes while generating rank on duplicates.
@akulakalyan1242
@akulakalyan1242 3 жыл бұрын
Select * from (select *, denserank() over (partition by empid order by sal desc)a,sal) src where src.a= Nth value;
@himanshugupta4807
@himanshugupta4807 3 жыл бұрын
@@akulakalyan1242 Hey Akula, query seems to be correct just one correction if you do partition over emp id then each salary will become unique and all records will have dense rank =1 so no need to use partition by clause.
@akulakalyan1242
@akulakalyan1242 3 жыл бұрын
@@himanshugupta4807 Then we can use dept id partition right
@vireshmohan7554
@vireshmohan7554 3 жыл бұрын
Hey, just wanted to let u knw that u r amazing.....The explanation Is just awesome...Thnx for such vids...Much Appreciated!!
@dhivyakamalakannan
@dhivyakamalakannan 3 жыл бұрын
Love this !! And I wish there was a love button in KZbin for subscribers
@anissiddiqui2649
@anissiddiqui2649 4 жыл бұрын
Congratulations for 9 thousand subscribers.
@raveendrakumar4499
@raveendrakumar4499 3 жыл бұрын
Excellent explanation, This is really helpful to understand the concept of this. Thank you so much for the video and keep posting interview based videos like this
@lucky4y4
@lucky4y4 3 жыл бұрын
Hi, I had watched your videos on SQL and it worked like a miracle for me. My logics gt better and better and finally I got the job offer that too on 31st of December 2020. I could never thank you. Thank you for your help. Keep posting keep helping keep growing. Thank you.
@crackconcepts
@crackconcepts 3 жыл бұрын
Congratulations 👏
@zubairahmed-om4vd
@zubairahmed-om4vd 3 жыл бұрын
Very informative may Allah bless u
@veenijeyasri2516
@veenijeyasri2516 3 жыл бұрын
Excellent mam, keep it up, expect more video from your page like this
@mallikarjunhagargi7830
@mallikarjunhagargi7830 3 жыл бұрын
You earned one subscriber dear thank you for the good content,,keep doing we appreciate
@mcaddit6802
@mcaddit6802 3 жыл бұрын
Why top 1 keyword doesn't support in most of the SQL compiler?
@ramanjaneyulum5739
@ramanjaneyulum5739 3 жыл бұрын
Select max(sal) from emp where salary not in(select distinct top 2 salary from emp order by salary describe)
@rajeshg3570
@rajeshg3570 3 жыл бұрын
This is very good explanation.. really like it.
@its_me7363
@its_me7363 4 жыл бұрын
very informative video...can you please make videos on more advanced SQL queries like partition, window function and pivoting table etc. ?
@equiwave80
@equiwave80 4 жыл бұрын
I have just just started to learn SQL. These videos will be very useful for for the me!!! BTW I have subscribed to your channel!!!
@ritika29
@ritika29 3 жыл бұрын
Instead of TOP 1 in the outer query can we use min() function?
@pratikkatke3570
@pratikkatke3570 3 жыл бұрын
Yes u can
@gopikrishna8521
@gopikrishna8521 3 жыл бұрын
Yes u can add min
@parthchoudhary4165
@parthchoudhary4165 3 жыл бұрын
Its really helpful .I understand in once ..tyku so much
@guruquebec
@guruquebec 3 жыл бұрын
Nice and thanks. You should try to teach to pass exams like 70-761 topic wise. since you have good explaining skills.
@anissiddiqui2649
@anissiddiqui2649 4 жыл бұрын
Congratulations to 10 thousands subscribers
@crackconcepts
@crackconcepts 4 жыл бұрын
Thank you😀
@ramanmanocha4800
@ramanmanocha4800 4 жыл бұрын
Amazing content, eagerly waiting for more videos!!
@RobbyTicknor
@RobbyTicknor 3 жыл бұрын
You could use a window function kind of like this select * from ( select *,ROW_NUMBER() OVER(ORDER BY sal ASC) AS Row# from emp ) SubQueryWithRowNum where Row# = 3
@ganeshkumaars859
@ganeshkumaars859 3 жыл бұрын
A DIRECT TOP 1 SELECTION MUST DO HOPE SO, AS WE ARE USING DESC AND AGIN MAKING IT ASC ,(the inner query must give result in asc by default)
@RupinderKaur-oq4kl
@RupinderKaur-oq4kl 2 жыл бұрын
Thanks alott 💖very easy to understand ☺️
@vishakhaborse7242
@vishakhaborse7242 3 жыл бұрын
Your teaching is really amazing...thank you
@lavanyasakhamuri9693
@lavanyasakhamuri9693 3 жыл бұрын
Very Nice explanation Mam.
@anirudhsodhani9397
@anirudhsodhani9397 3 жыл бұрын
what if we have a table that has many duplicate salary values? I think the better way to write the query is to fetch distinct N salary from the tables first ordered in descending order, and then finding out the min out of the N distinct salary/.
@anissiddiqui2649
@anissiddiqui2649 3 жыл бұрын
Congratulations for 11 thousands subscribers
@crackconcepts
@crackconcepts 3 жыл бұрын
Thank youu😊
@devanaidu9406
@devanaidu9406 4 жыл бұрын
Nice answer.. thank you for sharing your knowledge.❤️
@vasanthavasu8696
@vasanthavasu8696 3 жыл бұрын
We can use min(sal) in outer query instead of top 1. Am I wright?
@rushikeshkhandagale6472
@rushikeshkhandagale6472 3 жыл бұрын
hi thanks for your SQL query lectures they are very helpful.
@ranaprathap8292
@ranaprathap8292 3 жыл бұрын
Bro any requirements for SQL server pls reply me
@AbhishekSharma-hy4nl
@AbhishekSharma-hy4nl 4 жыл бұрын
Medium level leetcode question ... I just tried to solve it but couldn't. Thnx alot...
@sivaakumalla8687
@sivaakumalla8687 4 жыл бұрын
Nice explanation.👍 if it possible explain 'With '
@aravindg4801
@aravindg4801 4 жыл бұрын
Hi, From which version onwards TOP clause will work?? In oracle
@talhamuneer2599
@talhamuneer2599 4 жыл бұрын
Please Make Video Every Week!
@Faisal1504
@Faisal1504 3 жыл бұрын
Hi After the subquery I had to write as Temp - like give the subquery an alias then it worked. Is that correct way to do this qry? otherwise it says incorrect syntax near keyword order
@surendraavvaru8536
@surendraavvaru8536 3 жыл бұрын
Select * from (select ename,esal,dense_rank()over(order by sal desc)rank from Emp) where rank=#
@geniuschess7916
@geniuschess7916 3 жыл бұрын
perfect explanation ! very well understood :)
@shushmamalhotra6538
@shushmamalhotra6538 2 жыл бұрын
Mam plz provide a plat form where we can share some question in which we have problem related to SQL query
@akshitdhadwal
@akshitdhadwal 3 жыл бұрын
You explain things really well
@kumarraju9784
@kumarraju9784 2 жыл бұрын
Select from emp1 rownum
@beingrishi6450
@beingrishi6450 10 ай бұрын
Can it be resolved by using row_number OVER clause ORDER BY SALARY DESC ???
@Naresh_9182
@Naresh_9182 8 ай бұрын
I think this query is not supported by Oracle SQL developer 19thC version
@gbharathi5556
@gbharathi5556 2 жыл бұрын
Can u say what is the best approach to find n th highest salary....and explain it...
@unknowninformation3529
@unknowninformation3529 Жыл бұрын
What about the nth minimum topic? If there is max it should have minimum also right
@kevinj6279
@kevinj6279 3 жыл бұрын
We can use aggregate funcs like min(salary) and max(salary) right?
@Prisivi
@Prisivi 3 жыл бұрын
Yes
@kunaldarwesh2481
@kunaldarwesh2481 4 жыл бұрын
I like your explanation keep it up.
@arunachaleshwartiruvannama3188
@arunachaleshwartiruvannama3188 3 жыл бұрын
Useful one Thanks for this
@parshu3238
@parshu3238 3 жыл бұрын
Very well explain thank you very very much
@hajaaa100
@hajaaa100 3 жыл бұрын
For Nth highest salary in outer query do we need order by salary Asc.??? I feel not required but for 3rd highest it required. Correct me if I am wrong.
@vishalsaxena5081
@vishalsaxena5081 3 жыл бұрын
i have a query pls hlp me to solve this column_1 A A1,B2,C5 how can we insert in column like this and after that i want change where A1 is given i need only A pls help
@daminipatil8183
@daminipatil8183 4 жыл бұрын
Thank u so much Nice explanation
@daminipatil8183
@daminipatil8183 4 жыл бұрын
Best teaching.. Thank u
@jatinpant6992
@jatinpant6992 3 жыл бұрын
Mam, I am using MySQL and i am not able to use TOP Query, Please tell me what to do?
@jaisingh1641
@jaisingh1641 3 жыл бұрын
Why internal query order is descending , why can we keep it ASC , then then later we would not need to order again...
@siddharthkakade7779
@siddharthkakade7779 3 жыл бұрын
Select n salary and why do you select top 3 changes the question directly
@AsimSamDesiVines
@AsimSamDesiVines 3 жыл бұрын
Ma'am Will it work for repetitive salary data???
@suhas3785
@suhas3785 3 жыл бұрын
Thx for create video like this.....
@mercifulmedia9393
@mercifulmedia9393 4 жыл бұрын
Tittle mistake: "Nth" Don't mind.
@Vivek-gx6zd
@Vivek-gx6zd 2 жыл бұрын
select salary(select salary from employees order by salary dec)where rownum
@priyaingle832
@priyaingle832 3 жыл бұрын
Wow so easy explaination,
@shubhamingale4625
@shubhamingale4625 3 жыл бұрын
Is there any other trick in which we don't need use inner outer query
@vyshnavib8023
@vyshnavib8023 3 жыл бұрын
writing inner query only sufficient no mam..why can we write outerquery also..explan mam
@mazingTechnical
@mazingTechnical Жыл бұрын
select * from emp order by salary desc limit 2,1;
@xyz-vv5tg
@xyz-vv5tg 2 жыл бұрын
SELECT DISTINCT Sal FROM emps ORDER BY Sal LIMIT n; Here n =3 This might work as well.
@jayantmishra4270
@jayantmishra4270 2 жыл бұрын
3rd height salary:- Can i write like this?? :- Select salary from employees order by salary desc limit 2,1
@MaheshKumar-dj2nj
@MaheshKumar-dj2nj 3 жыл бұрын
i use that query subquery worked but above condition not working alert was invalid column name
@chinmayk2657
@chinmayk2657 2 жыл бұрын
Maam - need help - How to find people in a database who live in the same cities?
@sohrabkhan9823
@sohrabkhan9823 3 жыл бұрын
AOA, Urdu may banao na videos mam, or computr pr practical bhi sikhaiye plz
@Swatigowda0222
@Swatigowda0222 3 жыл бұрын
Can you make a video on abstraction in Java please? Because the way you’re teaching is understandable easily.
@rgvlogs1232
@rgvlogs1232 3 жыл бұрын
On this question , Can I use Select max (salary) from sal
@jagadishteluguvlogs
@jagadishteluguvlogs 2 жыл бұрын
Hlo mam I have one dought ... Given requirement is fetch the highest salary in a table so your are said top 1 salary in a table but but inner query results give 6000,5000,3000 like that but in this salary top 1 salary is 6000 but your said 3000 why mam..plz clearly say that mam IAM full confused..
@CS-Gowtham-R
@CS-Gowtham-R 3 жыл бұрын
Hi mam, I need one query. Write a query to select the nth row from the table. In MySQL. Please tell me mam❣️🙏
@raktimghosh7513
@raktimghosh7513 3 жыл бұрын
Select * from Table name where ROWNUM=N;
@CS-Gowtham-R
@CS-Gowtham-R 3 жыл бұрын
@@raktimghosh7513 No no it gives 0 to n rows. But I need only the specific nth row.
@sngparminder
@sngparminder 3 жыл бұрын
I tried but the top query but it is not working, I use toad & my sql
@v_naykp4168
@v_naykp4168 3 жыл бұрын
Select * from employees Order by Salary Desc Limit 3 ;
@sanjayisure4580
@sanjayisure4580 3 жыл бұрын
I am day by day going depressed bcz of not able to crack interview , they given scinario which is not solve by me , so please help me
@nikhilkadadevar5289
@nikhilkadadevar5289 4 жыл бұрын
Take 3 tables and solve query including all 3 tables mam
@channushahapur3019
@channushahapur3019 3 жыл бұрын
Can we use order by in the inner query??
@rushikeshkhandagale6472
@rushikeshkhandagale6472 3 жыл бұрын
what does mean Data integrity and how we check data integrity ?
@bhavinjoshi6780
@bhavinjoshi6780 3 жыл бұрын
Hi. How about using limit and offset?
@tanvirkaur5013
@tanvirkaur5013 3 жыл бұрын
Limit jus doesnt work in oracle.
@bhavinjoshi6780
@bhavinjoshi6780 3 жыл бұрын
@@tanvirkaur5013 But here we are talking about MySql. Right? Or no?
@vedantpatil3752
@vedantpatil3752 2 жыл бұрын
Thank you soo much god bless you
@souravnandy8385
@souravnandy8385 Жыл бұрын
Is there any other way to write this query?
@rayavenugopal8847
@rayavenugopal8847 3 жыл бұрын
Mam i need full course training on plsql. Can u?
@medhakhairnar6142
@medhakhairnar6142 3 жыл бұрын
Thanks ditto same question came in the interview
@mcaddit6802
@mcaddit6802 3 жыл бұрын
SELECT Salary FROM (SELECT distinct Salary FROM worker ORDER BY salary DESC LIMIT 2) as sal ORDER BY salary LIMIT 1;
@shutzzzzzz
@shutzzzzzz 4 жыл бұрын
What if we have duplicate data
@AsadAhmad-hd3gn
@AsadAhmad-hd3gn 3 жыл бұрын
pahle distinct use karo
@junirox1
@junirox1 4 жыл бұрын
Hello, really liked your videos. Thank you so much. I have more specific questions regarding SQL and I need help. Can I please email you. KIND REGARDS, JUN FROM UK
@mohammedhanifakolewale17
@mohammedhanifakolewale17 2 жыл бұрын
If department Id and salary in the same table how we can find hights salary with respect to department
@mohammedhanifakolewale17
@mohammedhanifakolewale17 2 жыл бұрын
I want only display highest salary with respect to department
@isankalp27
@isankalp27 3 жыл бұрын
Hi plz teach us SQL queries on the level of Class 10
@apamwamba
@apamwamba 6 ай бұрын
Given say: Person Salary tom 10 mary 20 hillary 30 joe 10 apam 200 cecilia 30 zuk 30 hope 80 euphrasia 100 Maureen 150 SELECT [Person] ,[Salary] FROM ( SELECT [Person] ,[Salary] ,DENSE_RANK() OVER (ORDER BY Salary) as ranking FROM [dbo].[sal_01] ) AS x WHERE x.ranking=3 RESULT: Person Salary hillary 30 cecilia 30 zuk 30
@trilok13579
@trilok13579 3 жыл бұрын
I want to display Name with Salary how can i do?
@pratiknarkhede1287
@pratiknarkhede1287 3 жыл бұрын
Is there a function called Top?
@sngparminder
@sngparminder 3 жыл бұрын
I wonder not, I tried this query sql toad but didn't worked
Solve 10 SQL Queries in 10 Minutes | SQL Interview Questions
14:53
Crack Concepts
Рет қаралды 76 М.
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
Part 1   How to find nth highest salary in sql
11:45
kudvenkat
Рет қаралды 2 МЛН
SQL Interview Question | Use Different Methods to Find the Nth Highest Salary
14:04
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН