Selecting from subquery in DQL

前端 未结 1 804
借酒劲吻你
借酒劲吻你 2020-12-10 06:51

I would like to perform a SELECT from the results of a subquery in DQL. The equivalent of doing the following in SQL:

SELECT * FROM ( SELECT foo1,foo2 FROM b         


        
相关标签:
1条回答
  • 2020-12-10 07:15

    Using DQL I'm pretty sure that's not possible, but if you really need it you might want to check:

    Doctrine Native SQL. (examples, permalink from the same page)

    It's much more complex but it also gives you the freedom to send native query and execute it (the tricky part for me was object hydration).

    On the other hand, if the last code segment resembles of anything what you're trying to achieve, there is a simpler way that requires no sub-queries:

    SELECT u
        FROM Utterance u LEFT JOIN u.recordings r
        WHERE r.speaker IS NULL OR r.speaker <> 5
        GROUP BY u.id HAVING COUNT(u) < 5
    

    Hope this helps...

    0 讨论(0)
提交回复
热议问题