SQL EXISTS condition in Symfony 1.4

382 views Asked by At

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?

1

There are 1 answers

0
Tomasz Madeyski On BEST ANSWER

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();