Row Number Function in MySQL | Important SQL Interview Question

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต
๐–๐š๐ง๐ญ ๐ญ๐จ ๐Œ๐š๐ฌ๐ญ๐ž๐ซ ๐’๐๐‹? ๐‹๐ž๐š๐ซ๐ง ๐’๐๐‹ ๐ญ๐ก๐ž ๐ซ๐ข๐ ๐ก๐ญ ๐ฐ๐š๐ฒ ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก ๐ญ๐ก๐ž ๐ฆ๐จ๐ฌ๐ญ ๐ฌ๐จ๐ฎ๐ ๐ก๐ญ ๐š๐Ÿ๐ญ๐ž๐ซ ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž - ๐’๐๐‹ ๐‚๐ก๐š๐ฆ๐ฉ๐ข๐จ๐ง๐ฌ ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ!

"๐€ 8 ๐ฐ๐ž๐ž๐ค ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ ๐๐ž๐ฌ๐ข๐ ๐ง๐ž๐ ๐ญ๐จ ๐ก๐ž๐ฅ๐ฉ ๐ฒ๐จ๐ฎ ๐œ๐ซ๐š๐œ๐ค ๐ญ๐ก๐ž ๐ข๐ง๐ญ๐ž๐ซ๐ฏ๐ข๐ž๐ฐ๐ฌ ๐จ๐Ÿ ๐ญ๐จ๐ฉ ๐ฉ๐ซ๐จ๐๐ฎ๐œ๐ญ ๐›๐š๐ฌ๐ž๐ ๐œ๐จ๐ฆ๐ฉ๐š๐ง๐ข๐ž๐ฌ ๐›๐ฒ ๐๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ข๐ง๐  ๐š ๐ญ๐ก๐จ๐ฎ๐ ๐ก๐ญ ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐š๐ง๐ ๐š๐ง ๐š๐ฉ๐ฉ๐ซ๐จ๐š๐œ๐ก ๐ญ๐จ ๐ฌ๐จ๐ฅ๐ฏ๐ž ๐š๐ง ๐ฎ๐ง๐ฌ๐ž๐ž๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ."

๐‡๐ž๐ซ๐ž ๐ข๐ฌ ๐ก๐จ๐ฐ ๐ฒ๐จ๐ฎ ๐œ๐š๐ง ๐ซ๐ž๐ ๐ข๐ฌ๐ญ๐ž๐ซ ๐Ÿ๐จ๐ซ ๐ญ๐ก๐ž ๐๐ซ๐จ๐ ๐ซ๐š๐ฆ -

๐–๐š๐ง๐ญ ๐ญ๐จ ๐ฅ๐ž๐š๐ซ๐ง ๐๐ข๐  ๐ƒ๐š๐ญ๐š ๐›๐ฒ ๐’๐ฎ๐ฆ๐ข๐ญ ๐’๐ข๐ซ?
๐œ๐ก๐ž๐œ๐ค๐จ๐ฎ๐ญ ๐ญ๐ก๐ž ๐›๐ข๐  ๐๐š๐ญ๐š ๐œ๐จ๐ฎ๐ซ๐ฌ๐ž ๐๐ž๐ญ๐š๐ข๐ฅ๐ฌ

I have trained over 20,000+ professionals in the field of Data Engineering in the last 5 years.

Row Number Function in MySQL | Important SQL Interview Question

In this video we will talk about how to use a row_number function in SQL and its industry use case.

Remember -
We should be using the order by clause
We can also use the partition by - but its optional
the row number starts from 1 for every partition

Do Like, Comment & Subscribe :)

๐—๐—ผ๐—ถ๐—ป ๐—บ๐—ฒ ๐—ผ๐—ป ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ:๐Ÿ”ฅ

#SQL #RDBMS #database #bigdata #dataengineering
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

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

pridename
ะะฒั‚ะพั€

Simple, smooth & very much practical example & tutorial.

sudarshanmhaisdhune
ะะฒั‚ะพั€

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๐Ÿ™๐Ÿป๐Ÿ™๐Ÿป๐Ÿ™๐Ÿป

piruanimesh
ะะฒั‚ะพั€

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');

learner-xutw
ะะฒั‚ะพั€

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

hafmouss
ะะฒั‚ะพั€

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 .. :)

saiakankshareddy
ะะฒั‚ะพั€

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.

Akashsingh-redk
ะะฒั‚ะพั€

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

brijesh
ะะฒั‚ะพั€

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

vikasgadhe
ะะฒั‚ะพั€

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

GauravSharmagvs
ะะฒั‚ะพั€

Very nice and cristal clear explanation sir of the row function appreciate your work. Congratulations you got one subscriber ๐ŸŽ‰ keep it up sir ๐Ÿ‘

krushnabelokar
ะะฒั‚ะพั€

Thank Q sir..

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

slyroy
ะะฒั‚ะพั€

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

kryurr
ะะฒั‚ะพั€

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??

udayptp
ะะฒั‚ะพั€

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

kmyamuna
ะะฒั‚ะพั€

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?

varuntirupati
ะะฒั‚ะพั€

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

arvindkumarsingh
ะะฒั‚ะพั€

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

ShivamSharma-oumz
ะะฒั‚ะพั€

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

itsall
ะะฒั‚ะพั€

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

TrueRDX
join shbcf.ru