DDC-1430: GROUP BY $alias in Oracle #1792

Open
opened 2026-01-22 13:26:03 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 18, 2011).

Jira issue originally created by user joksnet:

When creating a query with the QueryBuilder, the groupBy with only the alias doesn't work as expected.

It creates the group by with the ID only, but Oracle need all the fields to work.

The ORA-00979: not a GROUP BY expression error is returned.

From my SlotRepository I do:

$query = $this->createQueryBuilder('s')
    ->select('s, COUNT(a.id) AS agendas_count')
    ->leftJoin('s.agenda_slots', 'l')
    ->leftJoin('l.agenda', 'a')
    ->groupBy('s')
;

The SQL generated is:

SELECT s0*.id AS id0, s0_.hour_start AS hour_start1, s0_.hour_end AS hour_end2, s0_.active AS active3, COUNT(a1_.id) AS sclr4 FROM slot s0_ LEFT JOIN agenda_slot a2_ ON s0_.id = a2_.slot_id LEFT JOIN agenda a1_ ON a2_.agenda_id = a1_.id GROUP BY s0*.id

The SQL expected is:

SELECT s0*.id AS id0, s0_.hour_start AS hour_start1, s0_.hour_end AS hour_end2, s0_.active AS active3, COUNT(a1_.id) AS sclr4 FROM slot s0_ LEFT JOIN agenda_slot a2_ ON s0_.id = a2_.slot_id LEFT JOIN agenda a1_ ON a2_.agenda_id = a1_.id GROUP BY s0_.id, s0_.hour_start, s0_.hour_end, s0*.active

As workaround I include all fields manually.

Thank you,
Juan Manuel

Originally created by @doctrinebot on GitHub (Oct 18, 2011). Jira issue originally created by user joksnet: When creating a query with the _QueryBuilder_, the groupBy with only the alias doesn't work as expected. It creates the group by with the ID only, but Oracle need all the fields to work. The **ORA-00979: not a GROUP BY expression** error is returned. From my _SlotRepository_ I do: ``` $query = $this->createQueryBuilder('s') ->select('s, COUNT(a.id) AS agendas_count') ->leftJoin('s.agenda_slots', 'l') ->leftJoin('l.agenda', 'a') ->groupBy('s') ; ``` The SQL generated is: ``` sql SELECT s0*.id AS id0, s0_.hour_start AS hour_start1, s0_.hour_end AS hour_end2, s0_.active AS active3, COUNT(a1_.id) AS sclr4 FROM slot s0_ LEFT JOIN agenda_slot a2_ ON s0_.id = a2_.slot_id LEFT JOIN agenda a1_ ON a2_.agenda_id = a1_.id GROUP BY s0*.id ``` The SQL expected is: ``` sql SELECT s0*.id AS id0, s0_.hour_start AS hour_start1, s0_.hour_end AS hour_end2, s0_.active AS active3, COUNT(a1_.id) AS sclr4 FROM slot s0_ LEFT JOIN agenda_slot a2_ ON s0_.id = a2_.slot_id LEFT JOIN agenda a1_ ON a2_.agenda_id = a1_.id GROUP BY s0_.id, s0_.hour_start, s0_.hour_end, s0*.active ``` As workaround I include all fields manually. Thank you, Juan Manuel
admin added the Bug label 2026-01-22 13:26:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1792