Lec-70: Find Nth(1st,2nd,3rd....N) Highest Salary in SQL | Imp for Competitive & Placement exam

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • 👉Subscribe to our new channel: / @varunainashots
    ► Structured Query Language (SQL)(Complete Playlist):
    • Structured Query Langu...
    Other subject-wise playlist Links:
    --------------------------------------------------------------------------------------------------------------------------------------
    ►Design and Analysis of algorithms (DAA):
    • Design and Analysis of...
    ►Computer Architecture (Complete Playlist):
    • Computer Organization ...
    ► Theory of Computation
    • TOC(Theory of Computat...
    ►Artificial Intelligence:
    • Artificial Intelligenc...
    ►Computer Networks (Complete Playlist):
    • Computer Networks (Com...
    ►Operating System:
    • Operating System (Comp...
    ►Database Management System(Complete Playlist):
    • DBMS (Database Managem...
    ►Discrete Mathematics:
    • Discrete Mathematics
    ►Compiler Design:
    • Compiler Design (Compl...
    ►Number System:
    • Number system
    ►Cloud Computing & BIG Data:
    • Cloud Computing & BIG ...
    ►Software Engineering:
    • Software Engineering
    ►Data Structure:
    • Data Structure
    ►Graph Theory:
    • Graph Theory
    ►Programming in C:
    • C Programming
    ►Digital Logic:
    • Digital Logic (Complet...
    ---------------------------------------------------------------------------------------------------------------------------------------
    Our social media Links:
    ► Subscribe to us on TH-cam: / gatesmashers
    ►Subscribe to our new channel: / @varunainashots
    ► Like our page on Facebook: / gatesmashers
    ► Follow us on Instagram: / gate.smashers
    ► Follow us on Instagram: / varunainashots
    ► Follow us on Telegram: t.me/gatesmash...
    ► Follow us on Threads: www.threads.ne...
    --------------------------------------------------------------------------------------------------------------------------------------
    ►For Any Query, Suggestion or notes contribution:
    Email us at: gatesmashers2018@gmail.com
    #findNthHighestSalary#SQL#DBMS

ความคิดเห็น • 439

  • @aalirashid7178
    @aalirashid7178 4 ปีที่แล้ว +22

    GREAT EXPLANATION SIR IN WHOLE TH-cam DATABASE TUTORIALS I FEEL COMFORT WITH YOUR TUTORIALS ONLY STAY BLESSED LIKE SAME FROM PAKISTAN..

  • @Dhirendrakumar-dk1dt
    @Dhirendrakumar-dk1dt 2 ปีที่แล้ว +23

    Make it very easy to understand SQL. I have watched your all series of SQL and that helps me a lot to crack my interview, thank you very much sir for sharing your information ❤️

  • @nickbaib1839
    @nickbaib1839 5 ปีที่แล้ว +65

    Thank you so much!
    Continue the good job my friend!
    Greetings from Greece!

    • @GateSmashers
      @GateSmashers  5 ปีที่แล้ว +15

      wow..Thank you for your support..

  • @kushagrasahu8289
    @kushagrasahu8289 4 ปีที่แล้ว +47

    Your channel made SQL learning easy informative and fun🙌.
    I literally binge watched sql series.

  • @ayeshaameen3903
    @ayeshaameen3903 2 ปีที่แล้ว +9

    Wowwww You are a genius. No one have ever taught me like this..
    thank you so much for this one specially.

  • @ayushyadav4180
    @ayushyadav4180 3 ปีที่แล้ว +3

    i think in this world there would be no teacher other than him who don't need his students to know the language he is talking in i have seen comment of ppl from all over the world appreciating him.

  • @vinitakeer515
    @vinitakeer515 4 ปีที่แล้ว +2

    Thank you sir jb ap bolte hai k ye meri garrenti hai that puch line is superb.... God bless you

  • @varshasingh2748
    @varshasingh2748 5 ปีที่แล้ว +3

    Aapka lecture dekhe bina din achha ni jata your enthusiastic way of teaching fill Josh.

  • @ishangujarathi10
    @ishangujarathi10 ปีที่แล้ว +6

    One of the frequently asked question in interviews and placement/internships tests, thank you so such a perfect and easy explanation!!!

  • @rishabhsen9222
    @rishabhsen9222 3 ปีที่แล้ว +2

    I have a doubt...
    Inner query me to condition ye hai ki ' e2.salary > e1.salary '... To pehle e2 ki salary 10,000 ka comparison e1 ki salary k sath hoga to first comparison me to answer 0 hi ayega kyoki 10,000 e2 ki kic bhi salary se bda nhi hai... Jbki sir ne ulta comparison krke pehle comparison me answer 4 nikal diya... Sir ne ' e1.salary

  • @ranjeetpatra9212
    @ranjeetpatra9212 4 ปีที่แล้ว +11

    The way you elucidate this complex thing is really appreciable. Hats off ❤️

  • @annoniimous
    @annoniimous ปีที่แล้ว +36

    Alternate Answer for finding nth highest salary:
    SELECT Salary FROM employee
    ORDER BY Salary Desc
    limit 1 offset 0
    Here,
    limit means : how many output values you want to show on the screen ()
    offset means: let assume you want to show nth (4th) highest salary . In this case you will provide offset 3 which means you
    are leaving top 3 rows and you are choosing the 4th one . (( "offset means escaping the number of rows from top"))

    • @ajaysingh-kd4nt
      @ajaysingh-kd4nt ปีที่แล้ว +2

      limit does not work with oracle sql
      select * from (select * from employee order by salare desc) where rownum

    • @sr7821
      @sr7821 ปีที่แล้ว

      @@ajaysingh-kd4nt your code selects highest salary not Nth. I think this should work:
      select * from (select * from (select * from employee order by salary desc) where rownum

    • @ajaysingh-kd4nt
      @ajaysingh-kd4nt ปีที่แล้ว

      yea i was working on highest salary only
      @@sr7821

    • @ajaysingh-kd4nt
      @ajaysingh-kd4nt ปีที่แล้ว

      yes that might work filtering the Nth tuples and then getting the record
      @@sr7821

    • @AMANPATEL-g8v
      @AMANPATEL-g8v ปีที่แล้ว

      mnnit wle bhi aa rhe kyaa , biotech me kb se dbms aa gya bhai ??

  • @shubhamsood1406
    @shubhamsood1406 3 ปีที่แล้ว +10

    Another approach for MySQL users, also worked on duplicates salaries
    SELECT * from Employee WHERE salary= (SELECT DISTINCT salary from Employee ORDER BY salary DESC LIMIT N-1, 1);

    • @sanyogsalve6256
      @sanyogsalve6256 3 ปีที่แล้ว

      Thanks buddy it's easily understood

    • @sayalikawle4273
      @sayalikawle4273 2 ปีที่แล้ว

      your query is not firing giving errors

  • @vivekgupta5041
    @vivekgupta5041 3 ปีที่แล้ว +88

    No need of costly books !!! Much more matter than that provided by books !!!

    • @ShivamSharma-xk1yp
      @ShivamSharma-xk1yp 2 ปีที่แล้ว +1

      Right

    • @nitin9042
      @nitin9042 2 ปีที่แล้ว +2

      Average netpack at 200 can get you knowledge worth milli6

    • @ayushnegi5123
      @ayushnegi5123 3 หลายเดือนก่อน +1

      😢​@@ShivamSharma-xk1yp

  • @ravi6996
    @ravi6996 3 ปีที่แล้ว +4

    We can use LIMIT, OFFSET for yielding same results in case of finding nth highest

  • @bhuppidhamii
    @bhuppidhamii ปีที่แล้ว +2

    how does he explains every topic in a clear and comprehensible manner.😭💖

  • @surajkolekar7944
    @surajkolekar7944 3 ปีที่แล้ว

    select a_id,salary from agg as a1 where 3 = (select count(distinct(salary)) from agg as a2 where a2.salary > a1.salary);
    agg is table name..
    Thnk u for simplification.............

  • @MrAmmugadu
    @MrAmmugadu 5 ปีที่แล้ว +6

    Thank you so much sir, before I watched your video I was totally frustrated mind, bcoz I unable to understand subqueries,but after watching your vedio really I got more analysis points on subqueries, thank you again sir

  • @NishaOnYoutube
    @NishaOnYoutube 4 ปีที่แล้ว +1

    Sir the way you teach and explain is beyond amazing...because of you I got golden badge in hackerrank....

  • @souviknag
    @souviknag 2 ปีที่แล้ว +2

    I'm watching it very late. And there's only one thing that's going on in my mind, ITS BETTER LATE THAN NEVER!! I'm so glad that I found this channel after all. Subscribed!!

  • @krishna9971
    @krishna9971 2 ปีที่แล้ว +2

    Thank you sir, i was searching this concept from long ago, finally understood the working from your video only. Thank you for making sql easy.

  • @PythonisLove
    @PythonisLove 3 ปีที่แล้ว +10

    you cant believe, I can solve most dbms questions already after taking notes from your videos...I have never read a book

  • @anitha6661
    @anitha6661 3 ปีที่แล้ว +4

    Thank you so much for this video. I was struggling to understand the logic behind this and you just cleared all my doubts!!! : )

  • @Iamabhay_
    @Iamabhay_ ปีที่แล้ว

    This is very simple.......
    Select distinct salary from employee order by salary desc limit n-1, 1
    Here n is the nth highest. salary.

  • @nivi6414
    @nivi6414 5 ปีที่แล้ว +11

    Thanks a lot sir!. Been looking for the perfect explanation for months. Thanks again!

  • @yuvrajoberoi7834
    @yuvrajoberoi7834 4 ปีที่แล้ว +11

    No one has helped me more learning SQL queries than you sir.

  • @ankitbaiskhiyar3106
    @ankitbaiskhiyar3106 2 ปีที่แล้ว +1

    select max(salary) from Employee e1 where N-1 = (select count(distinct salary) from Employee e2 where e2.slaray > e1.salary (Leetcode)

  • @drawingloverswithsohana6194
    @drawingloverswithsohana6194 2 ปีที่แล้ว +1

    I like your all vedio and always watch your vedio when I fetch trouble to solve CSE DEPARTMENT related problem.

  • @OmitA25
    @OmitA25 5 ปีที่แล้ว +2

    Wow sir....its a great thing to have you on youtube....very informative video....thanku so much....

  • @gotamkartik21
    @gotamkartik21 3 ปีที่แล้ว +4

    thanks buddy, now i can understand this concept better.

  • @kedandu4209
    @kedandu4209 4 ปีที่แล้ว +1

    Well explained . I highly appreciate your talent and logic.

  • @kunalsingh5794
    @kunalsingh5794 5 ปีที่แล้ว +3

    Sir please also upload videos on digital electronic...
    ....... Please make video on sequential circuit....🙏🙏🙏🙏

  • @pradyutpanja5313
    @pradyutpanja5313 2 ปีที่แล้ว +2

    Thanks sir , last day in my interview 2nd highest salary was asked to me .my answer was right like....SELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee).. but i had a huge confusion on like how to find out the other cases 4th ,5th etc. but all confusions are totally cleared now. Thanks a lot sir.. now i have decided to watch your all videos related to SQL. and also i will recomend this to others who are actually facing on sql. such a nice tutorials...

  • @avtarchandra2407
    @avtarchandra2407 2 ปีที่แล้ว

    abb samjh me aya sirr ki Nth salary ku famous question hai ...kuki isme pura basic database grind ho jata hai ...love your effort

  • @rounak3239
    @rounak3239 5 ปีที่แล้ว +3

    Gurujee shandar jabardast zindabaad

  • @pruthvirajjadhav4049
    @pruthvirajjadhav4049 5 ปีที่แล้ว +1

    This logic is such that
    how many kids are elder than this child if there two child greater than this one then he is third .
    how to find the the second last child ?
    Q . how to find the second minimum salary ?
    ANS : try to get this .
    select salary ,id
    from emp e1
    where n-1 = (select salary count (distinct salary)
    from emp e2
    where e2.salary

  • @Arsaliqbal
    @Arsaliqbal 4 ปีที่แล้ว

    use distinct with sal in outer query to solve duplicate issue. (For 4th highest salary)
    select distinct salary
    from Emp e1
    where 3= (
    select count(distinct salary)
    from Emp e2
    where e2.salary > e1.salary
    )

    • @SantoshYadav-hj8kv
      @SantoshYadav-hj8kv ปีที่แล้ว

      @Arsaliqbal bro i am still geeting a duplicate salary.

  • @Ammuworld_himaja
    @Ammuworld_himaja 3 ปีที่แล้ว +1

    Thankyou very much, this is much helpful. Now i understood why that N-1 concept works just with the COUNT.

  • @shobhitgupta3885
    @shobhitgupta3885 3 ปีที่แล้ว

    Something like Select Min(Salary) from Emp AS e1 where N - 1 >= (Select Count(Salary) from Emp AS e2 where e2.Salary > e1.Salary) could also work.
    If 5000, 4000, 30000, 20000 ,20000, 10000 is expected order of salaries.

  • @hudachanna4918
    @hudachanna4918 ปีที่แล้ว +1

    You are amazing. Finally I understand how this works

  • @sushantsinha8216
    @sushantsinha8216 2 ปีที่แล้ว

    best channel ever over youtube for understanding sql tutorial

  • @rahulmungali7810
    @rahulmungali7810 ปีที่แล้ว

    One of the best video available in internet for correlated query👍👍

  • @ravikumar-wj3rr
    @ravikumar-wj3rr 3 ปีที่แล้ว +1

    you are great sir very best way to teach thank you sir

  • @AayushJain-mr6bx
    @AayushJain-mr6bx 4 ปีที่แล้ว +3

    Great playlist for DBMS. Very well explained. Kudos.

  • @shadabsiddiqui28
    @shadabsiddiqui28 2 ปีที่แล้ว

    sir apki jinti tareef ki jaye kam hai
    you are great

  • @nishu2166
    @nishu2166 2 ปีที่แล้ว

    Excellent sir....
    Really logic is very imp and that is clear... 👌👌💐

  • @jayasreecarey7843
    @jayasreecarey7843 2 ปีที่แล้ว +1

    Thanks ! Nice Explanation :)

  • @ranatalha3118
    @ranatalha3118 7 หลายเดือนก่อน

    Sir kindly check that ,Might be its easy query from your method.Please share your opinion.SELECT DISTINCT salary
    FROM employee
    ORDER BY salary DESC
    LIMIT 1 OFFSET 4;
    If we want 5th highest salary

  • @BEKKAMBHARATHASIMHAREDDY
    @BEKKAMBHARATHASIMHAREDDY ปีที่แล้ว +1

    BEST EXPLAINATION EVER AND EVER SIR
    THANK YOU SO MUCH
    🥰🥰🥰🥰

  • @fatimaiqra2169
    @fatimaiqra2169 2 ปีที่แล้ว

    Mny b try kiya bilkul thik ans aya ...best explanation sir

  • @sandhyajain7472
    @sandhyajain7472 4 ปีที่แล้ว +1

    Sir can you dive in a little more and explain why we did E2.salary > E1.salary not the other way around. Thanks for all the explanation that does not go over my head.

  • @lunatic792
    @lunatic792 3 ปีที่แล้ว +1

    Bhai behre insaan ko bhi samjha sakte hein, thank u so much.

  • @aayush5474
    @aayush5474 3 ปีที่แล้ว +10

    Take Away: Inorder to find Nth highest salary the salary should have N-1 salaries which are greater than given salary

  • @Diversifiedlady
    @Diversifiedlady 3 ปีที่แล้ว

    There are two tables salesman and customer.the question is - write a query to find those customers with their name and those salesman with their name and city who lives in the same city............ common attribute is salesman_id and city

  • @kritisk1
    @kritisk1 4 ปีที่แล้ว +4

    Thanks a ton, one of the best video which clearly explains the concept and logic behind the query.Im from Tamil Nadu but I was able to follow the language without any trouble because of the explanation

  • @yasmeenkarachiwala9612
    @yasmeenkarachiwala9612 5 ปีที่แล้ว +7

    Thank you so much Sir!
    Clear, concise teaching, making sure the fundamentals are understood !
    Greetings from San Francisco!

    • @GateSmashers
      @GateSmashers  5 ปีที่แล้ว +3

      thank you so much..its a great feeling that people from US appreciate my work. Thank you for your love and support..bless you

  • @Aritra20
    @Aritra20 ปีที่แล้ว

    select id, name, salary from emp e1 where N-1 = (select count(distinct(salary)) from emp e2 where e1.salary < e2.salary);

  • @pavangsk8404
    @pavangsk8404 ปีที่แล้ว

    kutha bhi dhekega tho samaj lega sir thank you so much... wonderful explanation

  • @pradeepkumar-qu1gc
    @pradeepkumar-qu1gc ปีที่แล้ว

    Very nice explanation friend. thanks a lot

  • @avishgoswami2141
    @avishgoswami2141 3 ปีที่แล้ว +1

    Man you nailed it...Hats off to you!!!

  • @AyurshiK
    @AyurshiK 2 ปีที่แล้ว

    great work sir beautifully explained difficult topics. it helped me a lot.

  • @manishKumar-tl2ee
    @manishKumar-tl2ee ปีที่แล้ว

    We can get the same using this Query also,
    SELECT DISTINCT salary AS nth_highest_salary FROM emp ORDER BY salary DESC LIMIT 1 OFFSET (N-1);

  • @chanchalarya983
    @chanchalarya983 2 ปีที่แล้ว

    THIS IS CALL GENIOUS WAY TO RIGHT QUERY

  • @neelesh621
    @neelesh621 3 ปีที่แล้ว

    Was seraching this..thnk u sir for this awesome level explanantion!!

  • @01kumarr
    @01kumarr 2 ปีที่แล้ว

    Superb much better than a book

  • @jovitalobo1273
    @jovitalobo1273 ปีที่แล้ว

    you explained this complex theory in awesome way. hats off to your efforts

  • @deepa8177
    @deepa8177 2 ปีที่แล้ว

    thanku for explaining each line got so much crystal clarity..

  • @deekshakhan4506
    @deekshakhan4506 2 ปีที่แล้ว +1

    such a nice concept i got from u sir🥰

  • @ashvinimeshram5242
    @ashvinimeshram5242 3 ปีที่แล้ว

    Thanks sir. This is very helpful. Now I am able to write quaries.🙏🙏🙏🙏

  • @LV-ni6tf
    @LV-ni6tf 3 ปีที่แล้ว +1

    Urs explaining way really super....

  • @shekharsalunke226
    @shekharsalunke226 3 ปีที่แล้ว

    Hi Sir,
    Thanksgiving your knowledge.. this method is too good.. 👍

  • @md.anisurrahman1723
    @md.anisurrahman1723 3 ปีที่แล้ว

    Nice explanation, to speak the truth.

  • @VickySharma-rz7he
    @VickySharma-rz7he 2 ปีที่แล้ว

    Great Explanation Sir thanks for such work

  • @harshjilka
    @harshjilka 3 ปีที่แล้ว +2

    Compiler confuse ho jayega : ye kya bat bani 😎🔥😂 OP

    • @iCyrus
      @iCyrus 3 ปีที่แล้ว

      😅🤣

  • @shrikrushnakarkhele9122
    @shrikrushnakarkhele9122 ปีที่แล้ว +1

    superb info sir

  • @sagarbhavsar7774
    @sagarbhavsar7774 2 ปีที่แล้ว

    very useful

  • @anujgrewal4456
    @anujgrewal4456 4 ปีที่แล้ว

    Very nice way Sir .......today i cleared this way ........

  • @Poorna10088
    @Poorna10088 3 ปีที่แล้ว +1

    Your explanation is awesome bro

  • @kumarsaheb
    @kumarsaheb ปีที่แล้ว

    best explanation ever.. God Bless !!

  • @mohammadrizwan3779
    @mohammadrizwan3779 2 ปีที่แล้ว

    Sir your video is excellent no 1 do one more thing if you give example on sql server management studio that would be much better than board.

  • @shashanksharma7747
    @shashanksharma7747 3 ปีที่แล้ว

    very good explanation underrated channel deserve more subscribers

  • @subhenduchsingh4981
    @subhenduchsingh4981 4 ปีที่แล้ว

    Really Appreciate ... Have understood the concert 👍👍

  • @zabilmaooz7780
    @zabilmaooz7780 3 ปีที่แล้ว

    my solution:
    select * from employee where salary = (select min(salary) from (select salary from employee order by salary desc limit 41) as salary_table);

  • @m.tayyab871
    @m.tayyab871 2 ปีที่แล้ว +1

    really found quality content...

  • @misunadiyan
    @misunadiyan 5 ปีที่แล้ว +4

    Great personality

  • @geetbawa990
    @geetbawa990 3 ปีที่แล้ว

    Excellent.... God bless u sir

  • @hireinnag2939
    @hireinnag2939 3 ปีที่แล้ว

    Great video. Very much explanatory!

  • @narenderreddyvanga8908
    @narenderreddyvanga8908 2 ปีที่แล้ว

    Excellent Explanation..👌

  • @digantaboro5227
    @digantaboro5227 5 ปีที่แล้ว +1

    Sir Error control ke baare me briefly video banayi ga please ?
    Sir why timer is necessary in Error control? Does their is possible to lost of header and flag ? If yes then whole data is corrupted.
    I'm confused

  • @neelkanthbk
    @neelkanthbk 4 ปีที่แล้ว +2

    Thank you so much, for explaining it such simplicity!!! You made it so easy to understand!!

  • @santoshsomu
    @santoshsomu ปีที่แล้ว

    thank you bro, i was able to understand easily with your detailed and examples explanation, thank you !

  • @renukarani7392
    @renukarani7392 3 ปีที่แล้ว

    Great explanation

  • @thesportslightmaker5988
    @thesportslightmaker5988 5 ปีที่แล้ว +3

    sir gate ka previous year questions bhi solve krro plzz

  • @mohammadnazim4515
    @mohammadnazim4515 5 ปีที่แล้ว

    Excellent sir, very easy to understand

  • @sakijilan7908
    @sakijilan7908 2 ปีที่แล้ว

    I have to say Sir ji, You are simply the BEST!!

  • @jitendraverma3783
    @jitendraverma3783 4 ปีที่แล้ว

    Great concept
    Learned something new
    Thanks 👍

  • @nehadubey7192
    @nehadubey7192 3 ปีที่แล้ว

    Nice..thanku for guidance

  • @suyash7450
    @suyash7450 ปีที่แล้ว

    yOU make it very easy to understand......

  • @sumenbhattacharyajee7091
    @sumenbhattacharyajee7091 4 ปีที่แล้ว

    Very Nicely you explained. 🙏

  • @anupkumarsahoo4506
    @anupkumarsahoo4506 2 ปีที่แล้ว

    Thank You Sir, It's just a great Explanation.