Row Number Function in MySQL | Important SQL Interview Question

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

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

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

    Checkout the Big Data course details here: trendytech.in/?referrer=youtube_sql15

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

      Link does work

    • @Nikhil-qi4oz
      @Nikhil-qi4oz 6 หลายเดือนก่อน

      Please continue SQLseries

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

    Excellent learning...getting so easy to understand and learning of SQL's most clever tricks....Thank you sir

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

    Simple, smooth & very much practical example & tutorial.

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

    Thank you so much sumit sir...Its quite easy to understand... Previously I had seen several vdo's but I can't get the actual purpose of using row_number & over clause... Some of the lectures they used the terms window - window which is quite tough to understand it... Thank you so much sir🙏🏻🙏🏻🙏🏻

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

    Thank you so much Sir, you explain better than many paid training and school

  • @Akashsingh-re9dk
    @Akashsingh-re9dk 2 ปีที่แล้ว +1

    select * from employee order by salary desc limit 4,1; One from many possible solution said by sumit sir to fetch the 5th highest salary. This querry too I got to know well from your sql sessions.

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

      But this doesn't show rownumber 5
      It's gives only 5th highest salary

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

      You can calculate the 5th highest salary in different ways
      1) by using order by clause with desc & then apply limit fn
      2) u can get it by using row_number and over clause also...

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

      To get 5th highest salary from dataset, It should be like:
      SELECT * FROM (select * from employee order by salary desc limit 5 offset 4) temptable LIMIT 1;

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

    thank you so much sir .... this video gave me nice clarification on row number ... your way of explaination is simply awesome ... and very helpful in understanding the topic .. :)

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

    thanks for such a wonderful tutorial.
    I have been following your content for a long time.

  • @learner-xu5tw
    @learner-xu5tw ปีที่แล้ว +2

    CREATE TABLE employee (
    firstname varchar(20),
    lastname varchar(20),
    age int,
    salary int,
    location varchar(20)
    );
    INSERT INTO employee VALUES ('sachin', 'sharma', 28, 10000, 'bangalore');
    INSERT INTO employee VALUES ('shane', 'warne', 30, 20000, 'bangalore');
    INSERT INTO employee VALUES ('rohit', 'sharma', 32, 30000, 'hyderabad');
    INSERT INTO employee VALUES ('shikhar', 'dhawan', 32, 25000, 'hyderabad');
    INSERT INTO employee VALUES ('rahul', 'dravid', 31, 20000, 'bangalore');
    INSERT INTO employee VALUES ('saurabh', 'ganguly', 32, 15000, 'pune');
    INSERT INTO employee VALUES ('kapil', 'dev',34, 10000, 'pune');

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

    As always Excellent tutorial. Thanks a lot for sharing this video.

  • @sibghaBiz
    @sibghaBiz 10 หลายเดือนก่อน

    you nailed it

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

    Very helpful. Thank you!

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

    Grt lesson on row number, I have one question if I want to assign row num as lets say 1 to all emp. Whose salary is 20000/- then how can you modify it? Here in your query if two emp are earning 20000/- then row num is assigning 1 and 2 but i want same row num for both as salary is same of both. I hope you're getting my confusion??

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

      we will learn Rank and Dense Rank in upcoming sessions. your question will be answered there.

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

    Thank you sir👍

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

    Fantastic

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

    Thank Q sir..
    If it is possible can you make one video related to Date functions and some scenarios

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

    Very nice and cristal clear explanation sir of the row function appreciate your work. Congratulations you got one subscriber 🎉 keep it up sir 👍

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

    thank u
    sir...

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

    @3:30 Sir, for me it is working even without sepcifying order by

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

    Hello Sir. Thank you for an excellant tutorial
    Please help me with following where we were finding 5th highest salary using -
    select * from ( select name , salary , row_number() over (order by salary desc) as key from emp ) temptable where rownum=2
    It says "NO DATA FOUND". Could you please help ?
    - Keyur

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

    Hi Sir, Thanks for the detailed explanation. I have a doubt, Can't, we use the row_number() without order by clause? or is it like we shouldn't use the row_number() function without partition by or order by clauses in the over Clause?

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

      order by is mandatory whereas partition by optional for all the windowing function

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

    Pls make videos on PLSQL

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

    Hi Sumit sir, one doubt here with partition by. There are 2 persons with same salary for banglore location. Is there any way to fetch both the person details for banglore location as there are multiple persons with the same highest salary

    • @4n3roid
      @4n3roid หลายเดือนก่อน

      Hi, if you want to display all employees who share the highest salary in a city, you should replace ROW_NUMBER() with RANK() or DENSE_RANK() as explained in the next video.
      SELECT * FROM (
      SELECT firstname, lastname, salary, location,
      RANK() OVER (PARTITION BY location ORDER BY salary DESC) as salary_rank
      FROM employee
      ) t1
      WHERE t1.salary_rank = 1;

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

    Sir please explain the temptable concept

    • @SrinivasMamidi-g2b
      @SrinivasMamidi-g2b ปีที่แล้ว

      we should give any alias name for that rownumber subquery , or else it will not allow u to fetch details from that, i suggest you to pls try code without giving name and u will come to know

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

    Incase of same salary in few rows, the row_number approach will fail. Right ?

    • @4n3roid
      @4n3roid หลายเดือนก่อน

      yes, just replace it with rank() or dense_rank()

  • @ShivamSharma-ou1mz
    @ShivamSharma-ou1mz 2 ปีที่แล้ว

    More correct way will be using Dense Rank function instead of Row Number for calculating Nth Salary

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

      Yes.. that we will cover in next section on how to optimize this solution

    • @SrinivasMamidi-g2b
      @SrinivasMamidi-g2b ปีที่แล้ว

      Yes, with Dense_rank we will get all the employess whose having same salary

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

    please cover 177 no leetcode question

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

    sir please also give use the table so dont need to write the query;

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

    why for bangalore 1 record, it should show 2 records as bangalore holds two 1st rank right ??

    • @4n3roid
      @4n3roid หลายเดือนก่อน

      Hi, if you want to display all employees who share the highest salary in a city, you should replace ROW_NUMBER() with RANK() or DENSE_RANK() as explained in the next video.
      SELECT * FROM (
      SELECT firstname, lastname, salary, location,
      RANK() OVER (PARTITION BY location ORDER BY salary DESC) as salary_rank
      FROM employee
      ) t1
      WHERE t1.salary_rank = 1;

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

    Lets assume the order by column is having NULL values then How will the rum_number() assign the values ?
    I have the same question for RANK and DENSE_Rank as well ?

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

    Pls send notes Sir

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

      Will try adding the link to it in the description section.

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

    please take regular expressions

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

    Samajh nhi aa raha

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

    plsql

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

    I got confusing 😭😭