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)
-quote end-
Basicly I want to select (for example) 10 rows beginning from 5th row.
Can anyone help me?
--
Best regards,
Jakub Cermak
ICQ 159971304
http://cermi.wz.cz
TOP is the equivalent in SQL Server, but it doesn't support an offset.
You can obtain the same behavior with a combination of derived tables
and ascending/descending ORDER BY clauses, something like this:
SELECT col1, col2
FROM
(
SELECT TOP 10 col1, col2
FROM
(
SELECT TOP 15 col1, col2
FROM table
ORDER BY col1 ASC
) AS derivedtable1
ORDER BY col1 DESC
) AS derivedtable2
ORDER BY col1 ASC
--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Do you want a separate statement, or just a clause within a statement?
You can use
SET ROWCOUNT 10
to limit all statements to affecting no more than 10 rows, so a SELECT will
return no more than 10, an UPDATE will update no more than 10, etc. All
statements will be affected until you use
SET ROWCOUNT 0
You can more read about SET ROWCOUNT in the Books Online.
Within a statement, you can use the TOP clause. The following statement
returns no more than 10 rows:
SELECT TOP 10 *
FROM MyTable
Please read about the TOP clause in the Books Online.
There is no way to says 'starting from the 5th row' because there is no such
thing as the 5th row. In a relational database table, the rows are not
ordered unless you request that the results be ordered by using ORDER BY.
So if you have a particular column that determines what the order is, you
could try something like this, which would give you the bottom 10 of the top
14, which is the same as the top 10 starting with the 5th.
SELECT TOP 10 *
FROM (SELECT TOP 14 * FROM MyTable ORDER BY OrderColumn) as T
ORDER BY OrderColumn DESC
--
HTH
Kalen Delaney, SQL Server MVP
"Jakub Cermak" <ja.c...@centrum.cz> wrote in message
news:eNsXzIhx...@TK2MSFTNGP04.phx.gbl...
In SQL 2005, you can use ROW_NUMBER() or RANK() functions & use them to get
the quota. In older versions, you might find some ideas here:
http://databases.aspfaq.com/database/how-do-i-page-through-a-recordset.html
--
Anith
You talk the talk but do you walk the walk? :( :)
Still toddling. Btw, interesting blog, Steve. Glad to see D4 ( and realSQL
too? ) is alive and kicking.
--
Anith
best,
steve
"Anith Sen" <an...@bizdatasolutions.com> wrote in message
news:%23Gd1noE...@TK2MSFTNGP03.phx.gbl...