Question

I'd like to express the following sql query in Symfony 1.4 using Doctrine's Query Builder :

select `user_agent`
from ticket
WHERE EXISTS (SELECT *
          FROM log
          WHERE ticket.id = log.ticket_id AND log.task_id = 1)

How I can express the "where exist....." condition?

Was it helpful?

Solution

You can use exists statement in where clause as other conditions. In your case it would look something like:

Doctrine_Core::getTable('ticket')->createQuery('t')
    ->select('user_agent')
    ->addWhere('exists(select * from log l where l.ticket_id = t.id AND l.task_id = 1')
    ->fetchArray();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top