[xquery-talk] return only latest version of an item

A. Steven Anderson steve at asanderson.com
Thu May 14 19:17:08 PDT 2009

> Which must be a bug. saxon returns a different result.

Perhaps, or I've lost something in translation from my simplified example.

>  Using distinct-values to group by id could be another option, though maybe
> not the fastest:
> for $id in distinct-values(/items//id)
> let $itemsById := /items/item[id = $id]
> return
>    $itemsById[version = max($itemsById/version)]
> You should have an index on id and version in any case.

This worked!  It's twice as fast as my original convoluted solution.

Many thanks to all who responded!!

A. Steven Anderson
Independent Consultant
steve at asanderson.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090514/185cb630/attachment.htm

More information about the talk mailing list