Doctrine 2: how do you use a subquery column (in the SELECT clause)

后端 未结 4 1847
天涯浪人
天涯浪人 2020-12-30 00:28

I\'m trying to do a simple select query with a subquery in the SELECT clause and have simply not found a way to do it. I\'ve tried with both DQL and with the QueryBuilder, n

4条回答
  •  自闭症患者
    2020-12-30 00:58

    $query = $qb->select('a')
        ->addSelect('(SELECT at.addresstypeName
                FROM e:Addresstype at
                WHERE at.addresstypeId = a.addresstypeId) AS addresstypeName'
            )
        ->from('e:Address', 'a')
        ->where('a.addressId = :addressId')
        ->setParameter('addressId', 1);
    

提交回复
热议问题