views:

57

answers:

2

Hello,

I need to compare one value to multiple other values (a query resulting in more than one element), therefore, if a value is included in some other values. In SQL there's the "IN" operator for that, but what about XQuery? Thanks for any hint :-)

A: 

let $values := ('1', '2', '3')

for $row in $table where $row/value = $values return $row

Or you could do this if you inlined it:

for $row in $table where $row/value = ('1', '2', '3') return $row

Michael Bazos
Thanks Michael, I've seen you replied before Oliver and your answer is correct too, yet I found Olivers post easier to understand, so I selected Oliver's post as answer. Hope you don't mind!
stefan.at.wpf
+1  A: 

The XQuery = operator behaves exactly as you describe:

3 = (1,2,3,4,5)

is true.

The eq operator is the version for comparing single values.

However if you are looking for whether a node $node is in a particular list of nodes $sequence, then you want

some $x in $sequence satisfies $x is $node
Oliver Hallam
Thank you very much, I'm new to XQuery and wasn't aware of that :-)
stefan.at.wpf