me.at.coding
me.at.coding

Reputation: 17724

XQuery: Compare one value to multiple values like SQL "in" command

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 :-)

Upvotes: 2

Views: 3393

Answers (2)

Michael Bazos
Michael Bazos

Reputation: 11

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

Upvotes: 1

Oliver Hallam
Oliver Hallam

Reputation: 4262

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

Upvotes: 5

Related Questions