1
0
mirror of synced 2024-12-15 07:36:03 +03:00
doctrine2/manual/docs/DQL (Doctrine Query Language) - Conditional expressions - Exists Expressions.php
2006-10-10 20:52:10 +00:00

27 lines
712 B
PHP

Syntax:
<div class='sql'>
<pre>
<i>operand</i> [NOT ]EXISTS (<i>subquery</i>)
</pre>
</div>
The EXISTS operator returns TRUE if the subquery returns one or more rows and FALSE otherwise. <br \>
<br \>
The NOT EXISTS operator returns TRUE if the subquery returns 0 rows and FALSE otherwise.<br \>
<br \>
Finding all articles which have readers:
<div class='sql'>
<pre>
FROM Article
WHERE EXISTS (FROM ReaderLog(id)
WHERE ReaderLog.article_id = Article.id)
</pre>
</div>
Finding all articles which don't have readers:
<div class='sql'>
<pre>
FROM Article
WHERE NOT EXISTS (FROM ReaderLog(id)
WHERE ReaderLog.article_id = Article.id)
</pre>
</div>