in reply to Re^2: Calculating previous/next from database
in thread Calculating previous/next from database

Only if this could work ...

-- changed "union" to "union all" select id from table where id > ? order by id asc limit 1 UNION ALL select id from table where id < ? order by id desc limit 1

... does not work in Sybase for (a) "order by" clause does not go with "union all" or in derived table creation; (b) there is no "limit" clause, just "rowcount" option per SQL session/transaction.

Replies are listed 'Best First'.
Re^4: Calculating previous/next from database
by psini (Deacon) on May 31, 2008 at 12:10 UTC

    You can do it in a little more convoluted way not using UNION at all:

    SELECT * FROM table WHERE id=(SELECT id FROM table WHERE id>? ORDER BY id ASC LIMIT 1) OR id=(SELECT id FROM table WHERE id<? ORDER BY id DESC LIMIT 1)

    Careful with that hash Eugene.