mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2793: Subquery into FROM #3497
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Nov 14, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user pcastrotigre:
I am trying to do something like:
This is not exactly the query i need, but that is the idea. The subquery into the FROM is not supported by the Query Builder neither the DQL because I am getting Error: Class '(' is not defined).
So how could I do this?
@doctrinebot commented on GitHub (Nov 14, 2013):
Comment created by @ocramius:
This is currently not supported by DQL. The workaround right now is to use:
SELECT count(A.*) FROM Acme\Bundle\Entity\User A WHERE A.id IN(SELECT u FROM Acme\Bundle\Entity\User u )@doctrinebot commented on GitHub (Nov 14, 2013):
Comment created by pcastrotigre:
What if my subquery is something like:
In this case I have a HAVING clause, so I must return more than 1 column in the subquery, and the IN clause cannot be used.
@doctrinebot commented on GitHub (Nov 14, 2013):
Comment created by stof:
DQL is about querying objects. Supporting subselects in the FROM clause means that the DQL parser is not able to build the result set mapping anymore (as the fields returned by the subquery may not match the object anymore).
This is why it cannot be supported (supporting it only for the case you run the query without the hydration is a no-go IMO as it would mean that the query parsing needs to be dependant of the execution mode).
In your case, the best solution is probably to run a SQL query instead (as you are getting a scalar, you don't need the ORM hydration anyway)
@doctrinebot commented on GitHub (Nov 14, 2013):
Issue was closed with resolution "Fixed"
@Ocramius commented on GitHub (Aug 3, 2020):
If you are doing more complex queries, you should most likely use SQL directly anyway.
@arthurlauck commented on GitHub (Oct 8, 2020):
Still not supporting subquery selects in from statement?
@FluffyDiscord commented on GitHub (Jan 12, 2023):
there is nothing complex about such a simple query
@hedocode commented on GitHub (Aug 25, 2023):
Non-sense when we know that Doctrine Paginator take a select with only entity id.
The use case is that you may want to select some more data to order by a calculus and then just subrequest to get entity's id only and still be a DQL query.
Same entity, still can do the mapping, idk why it's not supported.
@derrabus commented on GitHub (Aug 25, 2023):
Go ahead, build that feature if it's that simple.
@mpdude commented on GitHub (Aug 25, 2023):
I have recently been debugging some more complex queries with sub selects where MySQL 8 was way less performant than 5.7. So I wonder if this would help me 🙂
@hedocode commented on GitHub (Sep 1, 2023):
Sorry if that felt offensive, didn't mean to be (mean), just wanted to understand why in some cases we can't do such things. I would be glad to if I had time tbh.
Anyway, if anyone is going through the same problem as I did, I solved it by putting the calculus in the order directly so I don't have to select it and then the paginator works
instead of :