Thanks for the quick replies.<br><br>To answer Ken&#39;s question, I&#39;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&#39;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&#39;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">&lt;<a href="mailto:int19h@gmail.com">int19h@gmail.com</a>&gt;</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>
&lt;<a href="mailto:gkholman@cranesoftwrights.com">gkholman@cranesoftwrights.com</a>&gt; wrote:<br>
&gt; At 2009-05-14 14:18 -0400, A. Steven Anderson wrote:<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve got a pretty complex xquery that returns only the latest version of<br>
&gt;&gt; all items in a collection, but I know there has got to be a more efficient<br>
&gt;&gt; way to do it.<br>
&gt;&gt; ...<br>
&gt;&gt; What would be the most efficient way to do this?<br>
&gt;<br>
&gt; By which criteria are you trying to measure efficiency?<br>
&gt;<br>
&gt; Below is an example using max()<br>
&gt;<br>
&gt; I hope this helps.<br>
&gt;<br>
&gt; . . . . . . . . Ken<br>
&gt;<br>
&gt; t:\ftemp&gt;type steven.xml<br>
&gt; &lt;items&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;1&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 1&lt;/name&gt;<br>
&gt;      &lt;version&gt;1&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;1&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 1&lt;/name&gt;<br>
&gt;      &lt;version&gt;2&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;1&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 1&lt;/name&gt;<br>
&gt;      &lt;version&gt;3&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;2&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 2&lt;/name&gt;<br>
&gt;      &lt;version&gt;1&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;2&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 2&lt;/name&gt;<br>
&gt;      &lt;version&gt;2&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt;   &lt;item&gt;<br>
&gt;      &lt;id&gt;3&lt;/id&gt;<br>
&gt;      &lt;name&gt;item # 3&lt;/name&gt;<br>
&gt;      &lt;version&gt;1&lt;/version&gt;<br>
&gt;   &lt;/item&gt;<br>
&gt; &lt;/items&gt;<br>
&gt;<br>
&gt; t:\ftemp&gt;type steven.xq<br>
&gt; /items/item[version=max(/items/item/version)]<br>
<br>
</div></div>That doesn&#39;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&#39;s hard to tell the performance impact of this, since it&#39;s heavily<br>
implementation-dependant. Though I&#39;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>