tags:

views:

125

answers:

1

So I have an XQuery that looks something like this:

for $i in /*:rootElement
where $i/*:field = "test"
return $i

This query returns a lot of results, but I only really need one. How can I return just the first item in the result sequence?

+1  A: 
(for $i in /*:rootElement where $i/*:field = "test" return $i)[1]

On a side note, a better way to write this is to use step predicates:

/*:rootElement[*:field = "test"][1]
Pavel Minaev