Subject Re: [firebird-support] select datafield from mytable where lastchanged [is the biggest]
Author Luca Lafranchi
Hi again!

We found out the solution by ourselves: here it is for anybody having
the same problem:

select dset,mynr,datafield from mytable mt1
where not exists (
select 1 from mytable mt2
where mt2.dset=mt1.dset and mt2.mynr=mt1.mynr and
mt2.lastchanged>mt1.lastchanged
)


Luca Lafranchi wrote:

> Hi :)
>
> Assume I have a table with following fields:
>
> dset varchar(3)
> mynr varchar(10)
> lastchanged integer
> datafield integer
>
> Any combination of dset,mynr,lastchanged is unique.
>
> What I need is a subset of this table, with only the rows where
> lastchanged is the biggest for each combination of dset and mynr.
> An example:
>
> dset mynr lastchanged datafield
>
> 100 001 1 1234
> 100 001 2 32
> 100 001 3 324
> 100 001 4 1423
> 100 002 1 54
> 100 002 2 34
> 100 002 3 765
>
> Would give me
>
> 100 001 4 1423
> 100 002 3 765
>
> Is this possible using a single query?
>
>
> Thanks
> Luca
>
>
>
>
> To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>