Archives of the TeradataForum
Message Posted: Wed, 22 Oct 2008 @ 17:17:52 GMT
Subj: | | Re: First Row Function |
|
From: | | Dieter Noeth |
Hui Zhong wrote:
| The Select top n * from <table>; only returns the n rows specified. Is there a way to return the top 1 row for every group
by? | |
AFAIK there's no way to return that result based on your data. because rows in a table are always "unsorted".
So what's your definition of "first row"? If it's based on ordering by a third column:
select * from tab
qualify rank() over (partition by id order by ???) = 1
Maybe RANK has to be replaced by ROW_NUMBER, if the ordering is not unique. But RANK might have a better performance.
Dieter
|