Hi,
I need the equivalent for below mysql query :
select *from test limit 5, 20
I know that the below is possible in SQL Server :
select top 20 * from test where column1 not in (select top 5 column1 from test).
But my problem is I want a generic solution wherein I will not be aware of the columns available within the table. i.e I need a equivalent query without using any of the column names
Please advice

mysql limit equivalent
Tony128
The
LIMITclause can be used to constrain the number of rows returned by theSELECTstatement.LIMITtakes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements).With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
KirillA
on the sql server 2k syntax, if an identity is already part of the return columns in t, then you cannot introduct another identity into the table.
How do you work it in that case then
akka
This is crazy. LIMIT has been so useful and powerful in Oracle and MySQL, why will Microsoft not add it to their standard, or at least change TOP to handle the same functionality.
LIMIT type statements have made 500% improvements in my web apps. I have emulated in MSSQL, but it doesn't always work and when doing JOINs and ORDER BY's it really gets nasty.
Please tell me why Microsoft won't just see the light on this simple clause and add it ! ! !
firstfruits
jeremymarx
force_fx
select * from (select *, ROW_NUMBER() OVER(ORDER BY t.column1) as seq
from test as t) as t1 where t1.seq between 24*25 and 25*25
Is this best practice for "get page 25 with pagesize 25"
http://search.msn.com/results.aspx q=bill&first=625
http://searchpalette.com/spalette/24/25/bill
aleph
select t.*, identity(int, 1, 1) as seq
into #t
from test as t
order by t.column1
select *
from #t
where seq between 5 and 20
In SQL Server 2005, you can do the same using ROW_NUMBER() function.
select *
from (
select *, ROW_NUMBER() OVER(ORDER BY t.column1) as seq
from test as t
) as t1
where t1.seq between 5 and 20
subdigital
Conor Cunningham
SQL Server Query Optimization Development Lead