LIMIT 10 20 in SQL Server

0 votes

I'm trying to do something like :

SELECT * FROM table LIMIT 10,20

Or

SELECT * FROM table LIMIT 10 OFFSET 10

But using SQL Server

The only solution I found looks like overkill:

SELECT * FROM ( 
  SELECT *, ROW_NUMBER() OVER (ORDER BY name) as row FROM sys.databases 
 ) a WHERE row > 5 and row <= 10

Is there another way for me to do that ?

Sep 13, 2022 in Database by Kithuzzz
• 38,000 points
1,332 views

1 answer to this question.

0 votes
The LIMIT clause is not included in traditional SQL. It is supported by MySQL, PostgreSQL, and SQLite as a vendor extension to SQL. Similar capabilities in other database brands (such as TOP in Microsoft SQL Server) may exist, although they don't always function in the same way. In Microsoft SQL Server, using TOP to simulate the LIMIT clause is challenging. In some circumstances, it just doesn't work.

Microsoft SQL Server 2005 and later support the approach you demonstrated, using ROW NUMBER(). The best answer that just applies to the query is this one, for the time being. The first count + offset rows can also be fetched using TOP, and the first offset rows can then be sought past using the API.

I hope this helps you.
answered Sep 15, 2022 by narikkadan
• 63,600 points

Related Questions In Database

0 votes
1 answer

What are the different authentication modes in SQL Server? How can it be changed?

Windows mode and Mixed Mode – SQL ...READ MORE

answered Oct 29, 2018 in Database by Sahiti
• 6,370 points
1,221 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
2,000 views
0 votes
1 answer

SQL Server replaces LEFT JOIN for LEFT OUTER JOIN in view query

You are getting the joins confused and ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
1,503 views
0 votes
1 answer

Convert Rows to columns using 'Pivot' in SQL Server

You can use the PIVOT function to ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,070 points
1,618 views
0 votes
1 answer

Calculate Time Intersection to Correlate Sequences of Independent Events

I think this solution requires a CROSS JOIN implementation. ...READ MORE

answered Oct 26, 2018 in Power BI by Upasana
• 8,620 points
802 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
830 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,070 points
555 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
1,067 views
0 votes
1 answer

Use of contains() in sql server

The straightforward method is shown here. You ...READ MORE

answered Sep 10, 2022 in Database by narikkadan
• 63,600 points
1,052 views
0 votes
1 answer

Calculate a Running Total in SQL Server

The problem is that the SQL Server ...READ MORE

answered Sep 11, 2022 in Database by narikkadan
• 63,600 points
1,667 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