Thanks for the quick replies.<br><br>To answer Ken's question, I'm looking for time efficiency (i.e. quickest results returned) vs. space (i.e. RAM) efficiency.<br><br>Pavel, you were correct in your interpretation of my request; I'm looking to return the set of items with the greatest version number within the same id.<br>
<br>Unfortunately though, I tried your suggestion but only returned one item which was had the greatest version of all items.<br><br>As far as implementation, I'm querying eXist-db 1.2.5.<br><br>Any other suggestions?<br>
<br>Steve<br><br><div class="gmail_quote">On Thu, May 14, 2009 at 2:41 PM, Pavel Minaev <span dir="ltr"><<a href="mailto:int19h@gmail.com">int19h@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On Thu, May 14, 2009 at 11:23 AM, G. Ken Holman<br>
<<a href="mailto:gkholman@cranesoftwrights.com">gkholman@cranesoftwrights.com</a>> wrote:<br>
> At 2009-05-14 14:18 -0400, A. Steven Anderson wrote:<br>
>><br>
>> I've got a pretty complex xquery that returns only the latest version of<br>
>> all items in a collection, but I know there has got to be a more efficient<br>
>> way to do it.<br>
>> ...<br>
>> What would be the most efficient way to do this?<br>
><br>
> By which criteria are you trying to measure efficiency?<br>
><br>
> Below is an example using max()<br>
><br>
> I hope this helps.<br>
><br>
> . . . . . . . . Ken<br>
><br>
> t:\ftemp>type steven.xml<br>
> <items><br>
> <item><br>
> <id>1</id><br>
> <name>item # 1</name><br>
> <version>1</version><br>
> </item><br>
> <item><br>
> <id>1</id><br>
> <name>item # 1</name><br>
> <version>2</version><br>
> </item><br>
> <item><br>
> <id>1</id><br>
> <name>item # 1</name><br>
> <version>3</version><br>
> </item><br>
> <item><br>
> <id>2</id><br>
> <name>item # 2</name><br>
> <version>1</version><br>
> </item><br>
> <item><br>
> <id>2</id><br>
> <name>item # 2</name><br>
> <version>2</version><br>
> </item><br>
> <item><br>
> <id>3</id><br>
> <name>item # 3</name><br>
> <version>1</version><br>
> </item><br>
> </items><br>
><br>
> t:\ftemp>type steven.xq<br>
> /items/item[version=max(/items/item/version)]<br>
<br>
</div></div>That doesn't work as intended - it gets all items with version number<br>
equal to the highest version number for all items. What is needed (if<br>
I understood the original request correctly) is to only compare<br>
versions within group of items with the same id. Something like this:<br>
<br>
for $item in /items/item<br>
where $item/version = max(/items/item[id = $item/id]/version)<br>
return $item<br>
<br>
It's hard to tell the performance impact of this, since it's heavily<br>
implementation-dependant. Though I'd expect grouping operations (like<br>
xsl:for-each-group) to be easier to optimize, if they were there.<br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
<a href="mailto:talk@x-query.com">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br>
</div></div></blockquote></div><br><br>