[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

return only latest version of an item

Pavel Minaev int19h at gmail.com
Thu May 14 12:41:17 PDT 2009


  return only latest version of an item
On Thu, May 14, 2009 at 11:23 AM, G. Ken Holman
<http://x-query.com/mailman/listinfo/talk> wrote:
> At 2009-05-14 14:18 -0400, A. Steven Anderson wrote:
>>
>> I've got a pretty complex xquery that returns only the latest version of
>> all items in a collection, but I know there has got to be a more efficient
>> way to do it.
>> ...
>> What would be the most efficient way to do this?
>
> By which criteria are you trying to measure efficiency?
>
> Below is an example using max()
>
> I hope this helps.
>
> . . . . . . . . Ken
>
> t:\ftemp>type steven.xml
> <items>
>   <item>
>      <id>1</id>
>      <name>item # 1</name>
>      <version>1</version>
>   </item>
>   <item>
>      <id>1</id>
>      <name>item # 1</name>
>      <version>2</version>
>   </item>
>   <item>
>      <id>1</id>
>      <name>item # 1</name>
>      <version>3</version>
>   </item>
>   <item>
>      <id>2</id>
>      <name>item # 2</name>
>      <version>1</version>
>   </item>
>   <item>
>      <id>2</id>
>      <name>item # 2</name>
>      <version>2</version>
>   </item>
>   <item>
>      <id>3</id>
>      <name>item # 3</name>
>      <version>1</version>
>   </item>
> </items>
>
> t:\ftemp>type steven.xq
> /items/item[version=max(/items/item/version)]

That doesn't work as intended - it gets all items with version number
equal to the highest version number for all items. What is needed (if
I understood the original request correctly) is to only compare
versions within group of items with the same id. Something like this:

 for $item in /items/item
 where $item/version = max(/items/item[id = $item/id]/version)
 return $item

It's hard to tell the performance impact of this, since it's heavily
implementation-dependant. Though I'd expect grouping operations (like
xsl:for-each-group) to be easier to optimize, if they were there.



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.