Subject Re: [ib-support] SQL - getting first and last row
Author Svein Erling Tysvaer
select <something> from <table> t
where not exists(select 1 from <table> t2 where t2.id < t.id)
or not exists(select 1 from <table> t2 where t2.id > t.id)

This assumes there are no duplicates.

Set

At 13:50 10.09.2002 +0000, you wrote:
>Hello
>
>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.
>
>....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?
>
>Thanks
>
>David
>
>
>
>To unsubscribe from this group, send an email to:
>ib-support-unsubscribe@egroups.com
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/