15. Display 1st or last n rows (Top 50 SQL Interview Questions) | GeeksforGeeks

preview_player
Показать описание
This video is contributed by Trishaank Kandhi.

Please Like, Comment and Share the Video among your friends.

Install our Android App:

If you wish, translate into local language and help us reach millions of other geeks:

Follow us on Facebook:

And Twitter:

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

Very clearly explained sir, could u plz provide all 50 questions link sir🙏🙏🙏

koyavasudhalakshmi
Автор

very useful video thank you so much brother

bangaloredairies
Автор

Sir you said in last line very easy, very interesting but you make this easy and interesting for us thank you sir

saraswatirathore
Автор

Tnku... Please make more videos... Your videos are really helpful.... And geeks for geeks Sacha best sites for IT preparation exam and interviews...

getknowledgebite
Автор

For finding last 2 rows u can also use
Select * from table_name order by desc limit 2 ;

RohitGupta-doun
Автор

this query can be gneric if you dont know the exact count "select * from (select rownum r, name, salary from employees) where r=(select count(*) from employees) or r=(select count(*)-1 from employees);" for displaying the last two records

raghavansampa
Автор

Can u please explain same queries in SQL SERVER Also please ..rowid is not working in SQL SERVER

qjuzyfv
Автор

for the first n and last m rows:

WITH CTE AS
(
SELECT *, row_number() OVER(ORDER BY pk of that table) as rn, count(*) OVER () AS total_rows
FROM table1)

SELECT *
FROM CTE
WHERE rn <=n OR rn > total_rows - m

RahulMishra-pldq
Автор

for displaying last two rows, I have different answer. How about: select * from (select rownum r. ename, sal from emp) where r=(select count(*) from emp or r=(select count(*) from emp) - 1;

SumitKumarSK
Автор

can we use rownum by not making alias name?

priyanshnagar
Автор

what if we want last 3 records group wise.

akshayr
Автор

In mysql : (SELECT * FROM ename, sal ORDER BY emp_no ASC LIMIT 1) UNION (SELECT * FROM ename, sal ORDER BY emp_no DESC LIMIT 1);

chirag
Автор

Unfortunately, this 'rownum' keyword does not support in MYSQL.

saikatbiswas
Автор

Write queries that are non relying on specific database

RealSlimShady-umgf
Автор

At 3:55 you used > symbol but at first you told that we can't use >or= with rownum. 🤔

anjithiruveedhi
Автор

in the first question why can't we write :
select * from emp where rownum = 1 and rownum = (Select count(*) from emp);

ananyadwivedi
Автор

How to write generic sql query to select top 50% of records in a table .

mahammadshoyab
Автор

WRITE A QUERY TO DISPLAY ENAME OF EMPLOYEES WHO ARE HAVING EXACTLY ONE 'A' IN THEIR NAME?

kumarshivakar