How do I limit the amount of results returned in Sybase?

limit, sql, sybase

Solution

I believe you can do a `SET ROWCOUNT 10` first, then all queries in this session until a further `SET ROWCOUNT` will return no more than 10 rows. As a comment points out, this affects all following queries in the session (not just `SELECT`s!) until turned off (by setting to 0) or set differently -- this "global" effect makes it less handy than the typical `LIMIT` clause of other engines, which is inherently per-query, but, I don't think you can do anything about that.

Problem

I need to query a Sybase database which has a lot of data in it, and would like to set a limit so the DB stops the query after 10 results. The key thing is performance, so it would be no use if it searched all results and then then returned the last 10 results. Thanks in advance

Original source