10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: DQL (<strong>Doctrine</strong> Query Language) 142<br />

Listing<br />

9-96<br />

All and Any Expressions<br />

Syntax:<br />

operand comparison_operator ANY (subquery)<br />

operand comparison_operator SOME (subquery)<br />

operand comparison_operator ALL (subquery)<br />

An ALL conditional expression returns true if the comparison operation is true for all values<br />

in the result of the subquery or the result of the subquery is empty. An ALL conditional<br />

expression is false if the result of the comparison is false for at least one row, and is unknown<br />

if neither true nor false.<br />

Listing<br />

9-97<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('C')<br />

->where('C.col1 < ALL (FROM C2(col1))');<br />

An ANY conditional expression returns true if the comparison operation is true for some value<br />

in the result of the subquery. An ANY conditional expression is false if the result of the<br />

subquery is empty or if the comparison operation is false for every value in the result of the<br />

subquery, and is unknown if neither true nor false.<br />

Listing<br />

9-98<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('C')<br />

->where('C.col1 > ANY (FROM C2(col1))');<br />

The keyword SOME is an alias for ANY.<br />

Listing<br />

9-99<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('C')<br />

->where('C.col1 > SOME (FROM C2(col1))');<br />

Listing<br />

9-100<br />

The comparison operators that can be used with ALL or ANY conditional expressions are =,<br />

=, . The result of the subquery must be same type with the conditional<br />

expression.<br />

NOT IN is an alias for ALL. Thus, these two statem<strong>en</strong>ts are equal:<br />

FROM C<br />

WHERE C.col1 ALL (<br />

FROM C2(col1));<br />

FROM C<br />

WHERE C.col1 NOT IN (<br />

FROM C2(col1));<br />

Listing<br />

9-101<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('C')<br />

->where('C.col1 ALL (FROM C2(col1))');<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->from('C')<br />

->where('C.col1 NOT IN (FROM C2(col1))');<br />

Subqueries<br />

A subquery can contain any of the keywords or clauses that an ordinary SELECT query can<br />

contain.<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!