Someone who knows for sure should answer, but you =may= have a
problem using method 1, depending on how and when Sybase sorts
the rows.
I know the equivalent in Oracle will NOT work. It will pull the
first 5 rows it finds, THEN sort them. All you'll get is the
descending ordering of 5 arbitrarily selected rows.
Obviously, what you need is to get ALL the rows, SORT them, THEN
stop after printing the first 5. I'm not sure whether Sybase
acts in this way or not. I suspect it does, but I'm not sure.
> Using an example, to list top 5 richest people. This can be handles in three ways.
> 1. SET ROWCOUNT 5
> select name,sum(cash+stock+property) from table
> group by name
> oder by 2 DESC
> 2. use cursor to fetech the to 5
> 3. use sql , something similiar to the following
> select name,sum(a.cash+a.stock+a.property) money from table a
> where 5 > (select count(*) from table b where a.money < sum(b.cash+b.stock+b.property))
> group by name
> oder by money DESC
> My question is which on performs better? specially comparing the first two.
> Thanks,
> Leslie
--
+----------------------+---------------------------------------------+
| Alvin Sylvain | Your freedom of speech doesn't mean an |
| | obligation to listen. Mine, however, does! |
| Apologies for anti-spam address: see Org line for domain info. |
+--------------------------------------------------------------------+