Quantcast
Browsing all 35 articles
Browse latest View live

Answer by Troels Arvin for How to select the nth row in a SQL database table?

Contrary to what some of the answers claim, the SQL standard is not silent regarding this subject. Since SQL:2003, you have been able to use "window functions" to skip rows and limit result sets. And...

View Article


Answer by Nick Berardi for How to select the nth row in a SQL database table?

1 small change: n-1 instead of n.select *from thetablelimit n-1, 1

View Article


Answer by Henrik Gustafsson for How to select the nth row in a SQL database...

There are ways of doing this in optional parts of the standard, but a lot of databases support their own way of doing it.A really good site that talks about this and other things is...

View Article

Answer by Graeme Perrow for How to select the nth row in a SQL database table?

In Sybase SQL Anywhere:SELECT TOP 1 START AT n * from table ORDER BY whateverDon't forget the ORDER BY or it's meaningless.

View Article

Answer by John Dyer for How to select the nth row in a SQL database table?

But really, isn't all this really just parlor tricks for good database design in the first place? The few times I needed functionality like this it was for a simple one off query to make a quick...

View Article


Answer by Mark Harrison for How to select the nth row in a SQL database table?

Oracle:select * from (select foo from bar order by foo) where ROWNUM = x

View Article

Answer by Adam V for How to select the nth row in a SQL database table?

When we used to work in MSSQL 2000, we did what we called the "triple-flip":EDITEDDECLARE @InnerPageSize intDECLARE @OuterPageSize intDECLARE @Count intSELECT @Count = COUNT(<column>) FROM...

View Article

Answer by Neall for How to select the nth row in a SQL database table?

PostgreSQL supports windowing functions as defined by the SQL standard, but they're awkward, so most people use (the non-standard) LIMIT / OFFSET:SELECT *FROM mytableORDER BY somefieldLIMIT 1 OFFSET...

View Article


Answer by Tim for How to select the nth row in a SQL database table?

I suspect this is wildly inefficient but is quite a simple approach, which worked on a small dataset that I tried it on.select top 1 fieldfrom tablewhere field in (select top 5 field from table order...

View Article


Answer by Ellen Teapot for How to select the nth row in a SQL database table?

I'm not sure about any of the rest, but I know SQLite and MySQL don't have any "default" row ordering. In those two dialects, at least, the following snippet grabs the 15th entry from the_table,...

View Article

Answer by Greg Hurlman for How to select the nth row in a SQL database table?

Here's a generic version of a sproc I recently wrote for Oracle that allows for dynamic paging/sorting - HTH-- p_LowerBound = first row # in the returned set; if second page of 10 rows,-- this would be...

View Article

Answer by Kibbee for How to select the nth row in a SQL database table?

LIMIT n,1 doesn't work in MS SQL Server. I think it's just about the only major database that doesn't support that syntax. To be fair, it isn't part of the SQL standard, although it is so widely...

View Article

Answer by Andrew G. Johnson for How to select the nth row in a SQL database...

ADD:LIMIT n,1That will limit the results to one result starting at result n.

View Article


How to select the nth row in a SQL database table?

I'm interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can be achieved using the native...

View Article

Answer by Shah Fahad for How to select the nth row in a SQL database table?

To select the nth row up to the mth row within a specific range from a table in SQL, you can use the LIMIT clause along with the OFFSET clause. The OFFSET clause specifies the number of rows to skip...

View Article

Browsing all 35 articles
Browse latest View live