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...
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
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
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?
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. 😇🙏🏻😇
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
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 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.
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.
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
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..
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
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
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
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/.
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...
Yes. You’re right
@@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.
rows can have same salary and we may need to fetch all of them, so WITH TIES would be a better option
YES I NOTICED THAT AS WELL BUT WHAT IS THE REASON?
why s outside that bracket ? can you explain
Hi, do check out the whole SQL Playlist for more such videos!
Really wonderful explanation!
Nice explanation!! and please add the playlist url as well :)
Instead of
select top 1 from (subquery) order by sal desc ..
you can write
select min(sal) from (subquery)
Good one
Noice
@@chandrakanthotkar7262 Not necessary. It'll give the output
@@chandrakanthotkar7262 not needed
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
I had this in my mind..
Hn re limit use krne ka simple and easy
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
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?
I think you need a distinct for salary otherwise it will fail if few people have same salaries.
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. 😇🙏🏻😇
I’m so glad my videos helped you. Congratulations on the new job!
Shata 😂
dengda sariyagi
Bro any requirements for SQL pls reply me
Other Solution: select salary from (select salary from employee order by desc limit 3) order by salary asc limit 1;
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
@@Jagadish12345 you are right
For Oracle it's FETCH
@@Jagadish12345 similar way can you tell for sql plus
Select T.column_name, Dense_Rank() over (order by salary desc) as Rank from T_Tablename where Rank = N;
Geeks for geeks
;with rno as
(
Select Id, salary , dense_rank() over (order by salary) as salarycte
From emp
)
Select Id, salary from rno where salarycte = 3
Hello aashis
Easiest explanation ever... Thank you!
The bestest and the easieST place ON ENTIRE INTERNET TO FIND ANSWER. TYSM. HELPED ME IN INTERVIEW
Absolutely super today this is asked in interview for me and today i got this answer
Love this !! And I wish there was a love button in RUclips for subscribers
Hey, just wanted to let u knw that u r amazing.....The explanation Is just awesome...Thnx for such vids...Much Appreciated!!
Very informative may Allah bless u
Congratulations for 9 thousand subscribers.
Thanks alott 💖very easy to understand ☺️
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
This is very good explanation.. really like it.
We can use select * from(select *,rank() over(order by sal desc) rno from emp)src where rno = Nth value
This query is wrong
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.
Select * from (select *, denserank() over (partition by empid order by sal desc)a,sal) src where src.a= Nth value;
@@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.
@@himanshugupta4807 Then we can use dept id partition right
Its really helpful .I understand in once ..tyku so much
Very Nice explanation Mam.
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!!!
Excellent mam, keep it up, expect more video from your page like this
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.
Congratulations 👏
Wow so easy explaination,
You explain things really well
Why top 1 keyword doesn't support in most of the SQL compiler?
You earned one subscriber dear thank you for the good content,,keep doing we appreciate
Your teaching is really amazing...thank you
Congratulations to 10 thousands subscribers
Thank you😀
Thx for create video like this.....
Useful one Thanks for this
Select max(sal) from emp where salary not in(select distinct top 2 salary from emp order by salary describe)
very informative video...can you please make videos on more advanced SQL queries like partition, window function and pivoting table etc. ?
hi thanks for your SQL query lectures they are very helpful.
Bro any requirements for SQL server pls reply me
Nice answer.. thank you for sharing your knowledge.❤️
very insightful
Nice and thanks. You should try to teach to pass exams like 70-761 topic wise. since you have good explaining skills.
Tittle mistake: "Nth" Don't mind.
Thank you soo much god bless you
Nyc explaination
Please Make Video Every Week!
Amazing content, eagerly waiting for more videos!!
nice explanation.
Congratulations for 11 thousands subscribers
Thank youu😊
Thank u so much
Nice explanation
perfect explanation ! very well understood :)
Best teaching.. Thank u
Very well explain thank you very very much
Medium level leetcode question ... I just tried to solve it but couldn't. Thnx alot...
Select from emp1 rownum
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
select * from emp order by salary desc limit 2,1;
thanks a lot didi...
Mam plz provide a plat form where we can share some question in which we have problem related to SQL query
Excellent
Can u say what is the best approach to find n th highest salary....and explain it...
3rd height salary:-
Can i write like this?? :-
Select salary from employees order by salary desc limit 2,1
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..
Nice explanation.👍 if it possible explain 'With '
Thank you so much
Instead of TOP 1 in the outer query can we use min() function?
Yes u can
Yes u can add min
I think this query is not supported by Oracle SQL developer 19thC version
Nice work 🙌
I like your explanation keep it up.
Select * from employees
Order by Salary Desc
Limit 3 ;
Tqsm
AOA, Urdu may banao na videos mam, or computr pr practical bhi sikhaiye plz
Select * from (select ename,esal,dense_rank()over(order by sal desc)rank from Emp) where rank=#
Maam - need help - How to find people in a database who live in the same cities?
What about the nth minimum topic? If there is max it should have minimum also right
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)
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
thank a lot
Mam, I am using MySQL and i am not able to use TOP Query, Please tell me what to do?
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
select salary(select salary from employees order by salary dec)where rownum
We can use min(sal) in outer query instead of top 1. Am I wright?
Select n salary and why do you select top 3 changes the question directly
Can it be resolved by using row_number OVER clause ORDER BY SALARY DESC ???
Thank You Ma'am ...
Excellent...
SELECT DISTINCT Sal FROM emps ORDER BY Sal LIMIT n;
Here n =3
This might work as well.
Is there any other way to write this query?
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
We'll explained keep it madam
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/.
Take 3 tables and solve query including all 3 tables mam
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
Why internal query order is descending , why can we keep it ASC , then then later we would not need to order again...
Hi,
From which version onwards TOP clause will work?? In oracle
Is there any other trick in which we don't need use inner outer query
writing inner query only sufficient no mam..why can we write outerquery also..explan mam
Thanks ditto same question came in the interview
great
I tried but the top query but it is not working, I use toad & my sql
i use that query subquery worked but above condition not working alert was invalid column name
Mam i need full course training on plsql. Can u?
Your voice 💕
Can you start course on AWS kubernetes