[PR #801] [MERGED] Update SqlWalker.php fixed wrong GROUP BY clause on SQL Server platform #8727

Closed
opened 2026-01-22 16:01:21 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/801
Author: @flip111
Created: 9/26/2013
Status: Merged
Merged: 10/1/2013
Merged by: @guilhermeblanco

Base: masterHead: patch-4


📝 Commits (3)

  • 76fda95 Update SqlWalker.php fixed wrong GROUP BY clause on SQL Server platform
  • 72ae7f5 Changed GroupBy alias to real column name for all platforms and adjusted failing test accordingly. Has fallback in cases where real column name is not possible (example: Doctrine\Tests\ORM\Query\SelectSqlGenerationTest::testGroupBySupportsIdentificationVariable)
  • 228a501 Made the code prettier :)

📊 Changes

2 files changed (+11 additions, -2 deletions)

View changed files

📝 lib/Doctrine/ORM/Query/SqlWalker.php (+10 -0)
📝 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php (+1 -2)

📄 Description

Without this patch a query would like like:

SELECT c0_.Country AS sclr0
FROM Continent c0_ WITH (NOLOCK)
WHERE c0_.Country = 38
GROUP BY sclr0

Using the column alias in the GROUP BY clause. However this is not allowed on SQL Server. References:

  1. http://stackoverflow.com/a/3841804
  2. http://technet.microsoft.com/en-us/library/ms189499.aspx (Logical Processing Order of the SELECT statement)

The correct query should be:

SELECT c0_.Country AS sclr0
FROM Continent c0_ WITH (NOLOCK)
WHERE c0_.Country = 38
GROUP BY c0_.Country

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/801 **Author:** [@flip111](https://github.com/flip111) **Created:** 9/26/2013 **Status:** ✅ Merged **Merged:** 10/1/2013 **Merged by:** [@guilhermeblanco](https://github.com/guilhermeblanco) **Base:** `master` ← **Head:** `patch-4` --- ### 📝 Commits (3) - [`76fda95`](https://github.com/doctrine/orm/commit/76fda9562c8726d229ad90f24f159fee38309750) Update SqlWalker.php fixed wrong GROUP BY clause on SQL Server platform - [`72ae7f5`](https://github.com/doctrine/orm/commit/72ae7f5497adf0afdcf532c82fc8fc94e495226f) Changed GroupBy alias to real column name for all platforms and adjusted failing test accordingly. Has fallback in cases where real column name is not possible (example: Doctrine\Tests\ORM\Query\SelectSqlGenerationTest::testGroupBySupportsIdentificationVariable) - [`228a501`](https://github.com/doctrine/orm/commit/228a501014fa0e0de30019154bf755faf5786fc5) Made the code prettier :) ### 📊 Changes **2 files changed** (+11 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Query/SqlWalker.php` (+10 -0) 📝 `tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php` (+1 -2) </details> ### 📄 Description Without this patch a query would like like: ``` SELECT c0_.Country AS sclr0 FROM Continent c0_ WITH (NOLOCK) WHERE c0_.Country = 38 GROUP BY sclr0 ``` Using the column alias in the GROUP BY clause. However this is not allowed on SQL Server. References: 1. http://stackoverflow.com/a/3841804 2. http://technet.microsoft.com/en-us/library/ms189499.aspx (Logical Processing Order of the SELECT statement) The correct query should be: ``` SELECT c0_.Country AS sclr0 FROM Continent c0_ WITH (NOLOCK) WHERE c0_.Country = 38 GROUP BY c0_.Country ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:01:21 +01:00
admin closed this issue 2026-01-22 16:01:24 +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#8727