Doubt Distinct with Doctrine_query

Asked

Viewed 40 times

0

I have a table in mysql and I need to return unique values of this table only I am not able to create a Function or a query that adapts. The SQL statement in the bank would be like this and works right, only in Doctrine I can not do :

SELECT DISTINCT anodecorrente FROM ct_noticias WHERE categoria = 'Infanto' ORDER BY nt_id ASC

I have the class that maps the table in Doctrine as CtNoticias.

  • Help there guys !!! , any help is welcome.

1 answer

0

Thete the following DQL:

$this
    ->getEntityManager()
    ->createQuery('
        SELECT DISTINCT(c.anodecorrente)
        FROM CtNoticias c
        WHERE c.categoria = :categoria')
        ORDER BY c.ntId ASC
    ->setParameter('categoria', $categoria)
    ->getResult();

You may have to update the property names to the names of your class models CtNoticias.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.