stu
stu

Reputation: 8805

How do I get just the Nth row of data from sybase?

I have a table with multiple rows for each user. Each user will have the same number of rows but the row ids are all different for each user, so how I do get just the Nth row for a given user?

Assuming an order by user_id, row_id clause so you can be guaranteed a consistent order for any given user.

This is sybase 12 I'm working with here.

Upvotes: 1

Views: 11512

Answers (3)

Graeme Perrow
Graeme Perrow

Reputation: 57248

If you're using Sybase SQL Anywhere (it's not clear whether you're using SA or ASE), look up the start at and top clauses of the select statement here. For example:

select top 1 start at 7 * from mytable order by user_id, row_id

will retrieve the 7th row.

Upvotes: 3

vol7ron
vol7ron

Reputation: 42109

SYBASE should have windowing functions

SELECT * 
FROM   ( select row_number() over (order by user_id, row_id) as row, bar.*
         from   bar
       ) foo
WHERE  foo.row = 7

Upvotes: 1

Burcin
Burcin

Reputation: 985

if you can add seq_id column to that table that started from 0 for each user_id. You can query with this column.

Upvotes: 0

Related Questions