How to find second highest salary in SQL

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

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

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

    ✨Link to my SQL e-book: imojo.in/rkajq9
    ✨Link to 'Switch your career easily' e-book: imojo.in/1FL7KaG
    (Perfect for anyone willing to switch to a completely new field or to a different company in the Tech World)

  • @marshalljackson1385
    @marshalljackson1385 5 ปีที่แล้ว +26

    Without using a IDE to execute the SQL code, you did a great job in explaining your query code. Thank you.

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

    This series was extremely helpful for my placements

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

    LEAVE THE QUESTION ..OMG YOUR VOICE

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

    The way you use to explain the concept on paper is best way to understand more clear... Plzz keep going the same way.. it is very helpful specially for those who are beginners in IT , I’ll also share with people in need.. Thank you

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

    We can also use query select * from emp e1 where 1=(select count(salary) from emp e2 where e2.salary>e1.salary)

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

    I have all your SQL videos in my watch list will watch them on repeat you could be the main reason if I will be cracking my interview which is scheduled next week.

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

    Whoever you are , if you read my msg, then i want to say you.....Your voice is very beautiful and your explanation is crystal clear.
    Thank you very much and keep up the good work.

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

    This problem can also be solved by using inline view followed by a rownum attribute, but rownum is only supported by Oracle. But thanks for explanation.

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

    Select max(salary)from employees
    Where salary !=(select max (salary)from employees)
    Run this query easy to understand

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

    I really appreciate your efforts. I think we can do something like this without inner query -> select * from employees order by salary desc limit 1 offset 1(/limit 1,1);

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

    TH-cam was not that time we were doing study else we will have strong concepts with the help of such teacher. But still after 14 years of working experience these query were not such cristal clear to us.... But you did such magic with paper and pencil.... Really appreciatable....
    I like that way of reading and learning.... Keep doing it with other technical concept too.

  • @PriyaM-og6ji
    @PriyaM-og6ji 3 ปีที่แล้ว +2

    Great explanation and providing the different ways of solving the same problem is what most of us want. Thanks a lot.

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

    calm and cool explanation . i wish my teachers would explain like you.. but seriously u have a great and smooth voice. Thank you for explaining. Make more videos on database.

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

    Select * from employee order by salary desc limit 2;
    I think it is possible to fetch second highest salary

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

    Awesome explanation, thanks for making such an informative SQL interview question

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

    Damn good... explained so well and your voice is just amazing...

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

    For limit you can do , select salary from employee order by sal desc n-1,1 n varies accordingly

  • @shortsbypatvari
    @shortsbypatvari 6 หลายเดือนก่อน

    The way you teaches is so much good and easy ...other than your voice is treat for ears

  • @WelcomePrinceGaming
    @WelcomePrinceGaming 9 หลายเดือนก่อน

    simple query :
    Select salary from employee order by salary desc limit 1 offset 1:

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

    All those works fine with 2nd highest salary but these needs access logic if N changes, You could have solve these queries using rank and dense ranks in a generic way. Great explanations. Keep going.

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

    This was hard question for me before watching, but after watching your video..this question becomes so simple and quite easy.. thanks 😊😊😊
    Give more videos and best of luck to you.

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

      Thanks a lot. Glad it helped you

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

    Pen and paper wins. Hence proved by this awesome video by awesome voice. No need of fancy stuff.

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

    very good explanation without using any device , any body can understand it in one time, Loved it

  • @amirkhan-sv6zv
    @amirkhan-sv6zv 4 ปีที่แล้ว +5

    Hii ma'am...thank you so much for sharing this vedio.It's very useful to me..

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

    Please put more vedios on sql like this way......
    By the way your voice is sooo cute... 👏👏👏

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

    For selecting max salary using LIMIT --> SELECT salary FROM employee ORDER BY salary DESC LIMIT 1 ( doesn't this give us the max salary?)

    • @version3.028
      @version3.028 3 ปีที่แล้ว +1

      Bro same question....did u get any solution for it....

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

      @@version3.028 for selecting 2nd highest salary using limit -->
      SELECT salary FROM employee ORDER BY salary DESC LIMIT 1,1
      ==========================================================
      for selecting nth highest salary using limit -->
      SELECT salary FROM employee ORDER BY salary DESC LIMIT n,1

    • @version3.028
      @version3.028 3 ปีที่แล้ว

      @@pannagasudarshan6639 bro thanks,but i get it one hours ago....

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

      Limit does not work in oracle database,.....you can try with FETCH FIRST 2 ROWS ONLY....watch full syntax here.....

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

    FINDING Nth Highest Salary ??
    I think we can do it without an inner query
    SELECT Salary
    FROM Employee
    ORDER BY Salary DESC LIMIT 1 OFFSET (N-1)

  • @manish-gupta
    @manish-gupta 2 ปีที่แล้ว

    Crisp and crystal clear explanation. Thank you!!!

  • @madugulajoshi5050
    @madugulajoshi5050 8 หลายเดือนก่อน

    Select salary from employee order by salary desc limit 1 offset 1

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

    Thanks alot... i went through so many blogs.... but your explanation is crstal clear....

  • @shirdilalmutyala166
    @shirdilalmutyala166 2 หลายเดือนก่อน

    select * from employees
    where salary <
    (select max(salary) from employees)
    order by salary desc
    limit 1;

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

    Can you help me in this?
    Assume you have a table with the following fields:
    Emp_name Sal_Date Salary
    Also, assume that Salary credit data is populated in the table and that the data is available from 2015 to 2020.
    Write SQL query to print the name of the employee who got a max% hike in the annual salary from 2018 to 2019.

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

    Mam I have a Doubt.. In one of your Videos you have mentioned you CANT use "Where" when aggregate functions are used. Only HAVING should be used?But you have used where in the first example. Can you Clarify me ?

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

    i have 3 tables
    01) table employee (columns are empid,empname , depid)
    02) table Department ( columns are depid, dep name)
    03) table salary (columns are empid,amount,month).
    Q) get the empname , how don't get the salary in the month of December ?
    please let me the ans for this question

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

    SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET 1
    This will also work right..

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

    GREATEST EXPLANATION

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

    We can also use dense_rank()
    Much better in case we want nth salary

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

    Mam max(salary) is an aggregate function so we use having clause instead of where clause🤔

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

      Nope.... When u use aggregate in filter then we have to use HAVING.... Here she is just using "Salary" and not "max(salary)" so we have to go with WHERE clause only

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

      Yes....correct.....having max( salary) and only where salary....

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

    Is it necessary to write AS EMP after the inner query or the code shall execute correctly without it also? Please clarify?

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

      same question here. why is as emp used? i executed it without as emp and it throwed an error "Incorrect syntax near the keyword 'order'.
      " with as emp it is getting executed rightly.

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

    SELECT * FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1;
    Mam is this one of the way we can solve this quire

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

    We can write this with single query
    Select salary from emp order by salary desc limit 1, 1;

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

      I've tried your query in SQL SERVER MANAGEMENT STUDIO and it's not working for me.
      SELECT SAL FROM EMP
      ORDER BY SAL DESC LIMIT 1, 1;

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

    Hi.
    Can you please explain about performance tunning in sql.
    Thanks in Advance.

  • @NeerajGupta-oy2yp
    @NeerajGupta-oy2yp 2 ปีที่แล้ว

    Great Explanation...Impressed

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

    I didn't get any videos on youtube for such an easy methods

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

    madam aap bhaut acha explain karte ho thank you..............

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

    best channel for sql

  • @Arvindh-xp1lt
    @Arvindh-xp1lt 3 ปีที่แล้ว

    THANK YOU SO MUCH YOUR VIDEOS ARE VERY HELPFULL.......

  • @sivasankar-jp9tv
    @sivasankar-jp9tv 3 ปีที่แล้ว

    Really awesome but I have an doubt?
    Which one gives( max, limit,top) best performance and why?

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

    am i in heaven!! coz your voice seems like the voice of an angel

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

    Best teach thanks 🙏... please make blog on calculate the third highest salary or nth highest salary.
    Thank you again 🙏

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

    Please tell me one thing. WHERE works on rows not aggregated data, has been told by you in later video of differences so why we are using WHERE in place of HAVING.

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

    Thanks for this video .... Your voice is to good yaar...

  • @yes-pg5dy
    @yes-pg5dy 3 ปีที่แล้ว +1

    Excelnt mam pls do more on SQL and power bi also mam tq

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

    You are such a great teacher!

  • @PB-yk7pn
    @PB-yk7pn 3 ปีที่แล้ว

    Superb explanation great work 👍

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

    i have a problem as you said we can't use aagregarte functions with "where", then how did you use MAX(SALARY) and not used group by or having and why have you used ''WHERE', PLEASE ADDRESS THIS QUERY, SINCE it is very urgent.

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

    in first difference between video you mentioned that we cannot use WHERE if we are using any aggregate function and we should use HAVING instead and you said it again and again, So should we use it or please clear this doubt I wonder why no ever asked this question.

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

      A lot of people had this doubt so I made this one video to clear all doubts. th-cam.com/video/ggBXefD4UT8/w-d-xo.html
      Watch this and let me know in case of any doubts

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

    SELECT * FROM STUDENT WHERE MARKS=(SELECT MARKS FROM STUDENT GROUP BY MARKS ORDER BY MARKS DESC LIMIT 1,1);

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

    How can I find second min salary from a emp table.?
    I tried this way
    Select * from emp
    Where sal=(select min(sal) from emp
    Where sal>(select min(sal) from emp));
    Is there any other way? What if I want to find nth min salary and nth max salary from emp table

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

      Your query seems correct to me.👍
      For nth min salary you can do:
      SELECT TOP 1 salary FROM ( SELECT TOP n salary FROM employee ORDER BY salary ASC) ORDER BY salary DESC;
      Similarly you can do for nth max salary.

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

    Ma'am if u dont mind could u share this handwritten copy through drive link or anyother way. As its really helpful for interview preparation.

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

      Get full solutions here for all sql plsql interview questions.....

  • @kirankumar-ze4wi
    @kirankumar-ze4wi 2 ปีที่แล้ว

    can you make the video about performance tuning &
    ,sql agent concept..

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

    Can u explain about normalisation&denormolization..bcoz..this is the frequently asked questions in interview

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

    Thank you for explaining this. Make more videos.

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

    Great video. Thanks.

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

    Very nice. Very nice explanation

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

    Simple clear and to the point..
    Thanks for sharing...

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

    really great explanation....

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

    Fantastic explanation

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

    hi, one quick doubt, will it work ( LIMIT) even when we have duplicate salary in our list.. or do we need to use distinct keyword in the subquery.

  • @karthikreddy1836
    @karthikreddy1836 6 หลายเดือนก่อน

    We can using ranking function to do the same

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

    Short and sweet explanation.

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

    Great explanation

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

    madam konse server(DATABASE) ke liye konsi query CHALEGI ye to batao....?

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

    Nicely explained, well done 🙏

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

    This needed a DISTINCT, to overlook repetitive data.

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

    In the last question, finding 2nd largest in the last approach do we need to order by twice with TOP?

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

      Yes, in both the cases i.e. while using Limit as well as Top.

  • @RohitJadhav-rv3zj
    @RohitJadhav-rv3zj 3 ปีที่แล้ว

    Hey in one video you said that we cannot use where clause with aggregate functions , we need to use having clause.....but here you are using where with max function??

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

      Hi, a lot of people are confused because of this. So I made this video to clear the doubt.
      th-cam.com/video/ggBXefD4UT8/w-d-xo.html
      Watch this and all your doubts will be cleared.

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

    Super explaination..

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

    I am lazy person can anyone who made notes share them. I will pray for those.

  • @ShivaKumar-in8hn
    @ShivaKumar-in8hn 4 ปีที่แล้ว

    Omg nice voice plus great explanation ...

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

    Thanks a lot sharing thease. Your voice so sweet.

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

    Do we need to use group by salary also? Because if salary 7000 is repeating 2 times so 7000 will be at top two times by using order by salary desc.

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

    Can you explain for 3rd highest salary

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

      You can use rank function in with clause.....and then whatever rank u want u can fetch.....watch full solution here.....

  • @mohdrizwan-hi3dt
    @mohdrizwan-hi3dt 2 ปีที่แล้ว

    how you create this video , can you share the set up

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

    Hi
    Is there any difference between TOP and Limit ?

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

    Can we use Limit and Top in Oracle SQL

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

    Easiest explanation 💯 thank you..

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

    Super explanation ans your voice super

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

    while i am executing top command in sql command line it is giving error "
    FROM keyword not found where expected"

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

    You are an amazing tutor 😍❤️

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

    Thank You so much, this video helped to me.

  • @PankajYadav-yp4fb
    @PankajYadav-yp4fb 5 ปีที่แล้ว

    The way you explain i got it thanks ☺️👍👍👍

  • @satyabanukil779
    @satyabanukil779 3 หลายเดือนก่อน

    Wonderful. Can I do it ms access

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

    Please send me this type of question which can ask in interview? Its my Hamble request..

  • @NguyenThu-mi3pr
    @NguyenThu-mi3pr 4 ปีที่แล้ว

    I love all your explanations. But I hope u will improve your thumbnail. Handwritten notes is easy to see for explanations but bad for a thumbnail and makes me not want to click the video. Just a suggestion.

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

      Thank you for the suggestion!

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

    Nice voice and good explanation

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

    Mam how to write query to fetch the employees with its department_name can you please tell me as soon as possible

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

    Heyy....your voice is too good
    All the best !!👍

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

    When I use limit function it shows missing right parenthesis please help madam