DQL (Doctrine Query Language) - Conditional expressions - In expressions.php 792 Bytes
Newer Older
zYne's avatar
zYne committed
1 2 3
Syntax:
<div class='sql'>
<pre>
zYne's avatar
zYne committed
4
<i>operand</i> IN (<i>subquery</i>|<i>value list</i>)
zYne's avatar
zYne committed
5 6 7
</pre>
</div>
An IN conditional expression returns true if the <i>operand</i> is found from result of the <i>subquery</i>
zYne's avatar
zYne committed
8
or if its in the specificied comma separated <i>value list</i>, hence the IN expression is always false if the result of the subquery
zYne's avatar
zYne committed
9 10
is empty.

zYne's avatar
zYne committed
11 12
When <i>value list</i> is being used there must be at least one element in that list.

zYne's avatar
zYne committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<div class='sql'>
<pre>
FROM C1 WHERE C1.col1 IN (FROM C2(col1));

FROM User WHERE User.id IN (1,3,4,5)
</pre>
</div>

The keyword IN is an alias for = ANY. Thus, these two statements are equal:
<div class='sql'>
<pre>
FROM C1 WHERE C1.col1 = ANY (FROM C2(col1));
FROM C1 WHERE C1.col1 IN    (FROM C2(col1));
</pre>
</div>