Subject Re: [firebird-support] Select in select
Author Mercea Paul
On 2012.02.25 12:19 PM, Svein Erling Tysvær wrote:
>
> Not sure if it is any better when you only need two fields, but you
> could, of course, use a CTE:
>
> WITH TMP_INVOICE(ID_INVOICE, AMOUNT_LAST_INVOICE,
> CURRENCY_LAST_INVOICE) AS
> (SELECT I.ID_INVOICE, I.AMOUNT, I.CURRENCY
> FROM INVOICE I
> LEFT JOIN INVOCE I2 ON I.ID_INVOICE = I2.ID_INVOICE
> AND I.SomeUniqueField < I2.SomeUniqueField ...
> WHERE I2.ID_INVOICE IS NULL)
>
If I understand correct the request, this is correct only if records are
in chronologically order.
There is possible to have records with row id smaler but date field
value greater (the invoice arrive later into the office), in that case
should compare date's fields and not rowid.

Hth,

Paul MERCEA

E-mail: paul.mercea@...

___________________________________________



[Non-text portions of this message have been removed]