How to select the nth row in a SQL database table

0 votes
Sep 27, 2019 in Database by Daric
• 500 points
17,683 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

 

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 in Database by Kithuzzz
• 10,840 points
47 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 in Database by Neha
• 8,920 points
101 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 in Database by Kithuzzz
• 10,840 points
33 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 in Database by Kithuzzz
• 10,840 points
24 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 in Database by Kithuzzz
• 10,840 points
75 views
0 votes
0 answers
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 in Database by Kithuzzz
• 10,840 points
15 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
712 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
343 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP