How to select the nth row in a SQL database table

0 votes
Sep 27, 2019 in Database by Daric
• 500 points
24,788 views

2 answers to this question.

0 votes

To select nth row type the below query:

SELECT * FROM (
  SELECT
    ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber,
    columns
  FROM tablename
) AS foo
WHERE rownumber <= n

If you need to know more about SQL, it is recommended to go for the SQL Online Course today.

answered Sep 27, 2019 by Omaiz
• 560 points
0 votes
SELECT * FROM (
SELECT 
ID, NAME, ROW_NUMBER() OVER(ORDER BY ID DESC) AS ROW
FROM TABLE 
) AS TMP 
WHERE ROW = n
answered Apr 23, 2020 by anand
• 140 points

Related Questions In Database

0 votes
0 answers

How to select the last record of a table in SQL?

Here is an example of code that ...READ MORE

Aug 23, 2022 in Database by Kithuzzz
• 38,010 points
807 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,060 points
495 views
0 votes
0 answers

How to create a table from select query result in SQL Server 2008

I tried to build a table from ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,010 points
593 views
0 votes
0 answers

How can I select the first day of a month in SQL?

I only need to choose the given ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,010 points
367 views
0 votes
0 answers

How to find sum of multiple columns in a table in SQL Server 2005?

I have a table Emp which has these rows: Emp_cd ...READ MORE

Aug 19, 2022 in Database by Kithuzzz
• 38,010 points
1,325 views
0 votes
0 answers

How to fetch the nth highest salary from a table without using TOP and sub-query?

I was recently requested to create a ...READ MORE

Aug 25, 2022 in Database by Kithuzzz
• 38,010 points
1,059 views
0 votes
0 answers

How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

In one ALTER TABLE statement, I would ...READ MORE

Sep 2, 2022 in Database by Kithuzzz
• 38,010 points
476 views
0 votes
0 answers
0 votes
1 answer

Query to list number of records in each table in a database

Use the below code to list number of ...READ MORE

answered Oct 11, 2019 in Database by Omaiz
• 560 points
1,219 views
0 votes
1 answer

How do I reset a sequence in Oracle?

 If you want to set it to ...READ MORE

answered Sep 27, 2019 in Database by Omaiz
• 560 points
641 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP