0

How to select in Sybase data between rows, e.g.: from row 100 to row 150

TOP 50 will give me from 0 to 50, but I want from 100 to 150.

This link shows for Oracle and MySQL, but not for sybase.

The @@rowcount will specify the count, or am I wrong?

Community
  • 1
  • 1
Moudiz
  • 7,211
  • 22
  • 78
  • 156

1 Answers1

1

It would go something like this ....

    select top 50 * from (
        select top 150 * from dbo.YourTable
    ) src order by ID desc

You want to select 150 rows order by desc,

So it would go 150, 149 ... 3, 2, 1 ... from that you will select top 50 ... meaning from 150 to 100.

Veljko89
  • 1,813
  • 3
  • 28
  • 43
  • i got error :An ORDER BY clause is not allowed in a derived table. – Moudiz Jan 26 '17 at 11:54
  • @Moudiz check now, I changed a query a bit – Veljko89 Jan 26 '17 at 12:28
  • I want by row not by id , is that possible ? – Moudiz Jan 26 '17 at 12:32
  • Think so, just change order by then ... if you select top 150, and then just desc it ... that should do the trick – Veljko89 Jan 26 '17 at 12:35
  • it gave wrong result , it should give 3,4 , it gave 6,7 – Moudiz Jan 26 '17 at 12:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134074/discussion-between-veljko89-and-moudiz). – Veljko89 Jan 26 '17 at 12:51
  • I cannot , because priviliges issue on pc , chating wont load , please lets continue here – Moudiz Jan 26 '17 at 12:53
  • I am not that sure about sybase stuff, they are alike SQL server, but checking other SO answers, can you make something like answer from http://stackoverflow.com/questions/16608469/how-to-set-row-number-in-sybase-query ... get those 150 desc into temp table, then select top 50 asc? – Veljko89 Jan 26 '17 at 12:57