# [RFC] [Discussion] Enable selecting a group by column name in PDO::FETCH_GROUP

- Thread: https://externals.io/message/133179
- Original archive: https://news-web.php.net/php.internals/133179
- Started by Hassan Ahmed on 2026-11-22T07:30:59+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #133179 — Hassan Ahmed — 2026-11-22T07:30:59+00:00

URL: https://externals.io/message/133179#133179

Hi internals,

I would like to discuss adding the ability to select the group key when
selecting PDO::FETCH_GROUP attribute.

Basically, the flag will let PDO group results by the very first selected
column in the written query. This means that you must get the grouping key
at the first of your query.

By allowing fetchAll method to accept a second query when use the
FETCH_GROUP attr, we can now pick a specific column to group the output
results with.

There are no BC issues, skipping providing the second argument will use the
default behavior.

Tho, there are some point that I'm not sure of yet, like when the user
select a column name that is not exists, do we need to raise an exception
or ignore it.

I'd wrote a WIP proposal for this https://github.com/php/php-src/pull/25514
waiting your thoughts about it.

Best regards,
Hassan
