i have in Symfony 1.4 and Doctrine 1.2 such query:
$this->query = Doctrine_Core::getTable('News')
->createQuery('a')->leftJoin('Tag c')->where('c.tag_id = 2' ) ->execute();
This return for example:
| id_news | tag | title_news |
| 1 | 1 | title1 |
| 1 | 2 | title1 |
| 2 | 1 | title2 |
| 2 | 2 | title2 |
| 2 | 3 | title2 |
etc.
how can i make this:
| id_news | tag | title_news |
| 1 | xxxx| title1 |
| 2 | xxxx| title2 |
(only one (1 and title1) and (2 and title2))
i dont would like repeat data from table news (id_news, title_news). tag not necessarily return.
use the ‘WITH’ clause in your join statement.
should be something like
->leftJoin('Tag c WITH c.tag_id = 2')or group the results by the news id
->groupBy('id_news')