0

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 Answers1

2

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();
Tomasz Madeyski
  • 10,742
  • 3
  • 50
  • 62