Question: I have this query :

```
        $qb = $this->_em->createQueryBuilder();
        $qb->select('DISTINCT c.account')
                ->from('ThanksWhoProjectBundle:Comment', 'c')
                ->leftjoin('c.account', 'a')
                ->where('c.conversation = ?1')
                ->setParameters(array(1 => $conversation));
        return $qb->getQuery()->getResult();

```

So, the field `Comment.account` is a foreign key with my entity `Account`. I just need to retrieve all differents accounts who are in the conversation.

So, i want to only select the field `c.account`, but with this query have this error :

```
[Semantical Error] line 0, col 18 near &#039;account FROM&#039;: Error: Invalid PathExpression. Must be a StateFieldPathExpression. (500 Internal Server Error)

```

How can i do that ?

Answer: 
You need to use `DISTINCT` on the joined `account` `id`:

```
$qb = $this->_em->createQueryBuilder();
        $qb->select('DISTINCT a.id') // note 'a.id'
                ->from('ThanksWhoProjectBundle:Comment', 'c')
                ->leftjoin('c.account', 'a')
                ->where('c.conversation = ?1')
                ->setParameters(array(1 => $conversation));
        return $qb->getQuery()->getResult();

```

From the official documentation: <http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html>
"Making this possible is very simple. Just add the property shopId to the product entity as any other field mapping property, and so that it corresponds with the actual column in the database table. Make sure you put this property ABOVE the association property “shop”, otherwise it will not work as expected."

<http://pietervogelaar.nl/doctrine-2-use-foreign-key-as-field-in-dql/>

Note: I am using a custom hydrator. I did run into issues when using this with the default hydrator.

Great, no more unnecessary joins for read only queries! I'm not sure what the effects would be when trying to update the objects in a result set.