Subject Re: [ib-support] SQL - getting first and last row
Author Martijn Tonies
Hi David,

> I have a table with columns:
>
> ID (PK - generator'ed), timestamp.
>
> Is it possible to get the first and last rows in one query? i.e. the
> highest and lowest ID, or the earliest and latest timestamp - either
> method should return the same rows.

Have a look at the syntax for FIRST - take only 1 row, order it
ASC and UNION the result with only 1 row order it DESC.

> ....also, I assume I would need another query to get the row count
> (Select count(*) from myTable) - is this the most efficient way of
> getting the row count?

Yes - and it's slow :)


With regards,

Martijn Tonies
InterBase Workbench - the developer tool for InterBase
http://www.upscene.com

Firebird Workbench - the developer tool for Firebird
http://www.upscene.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."