bug: GROUP BY fails on strict MySQL ONLY_FULL_GROUP_BY #59

Closed
opened 2026-06-28 15:36:28 +00:00 by jmiller · 2 comments
Owner

Summary

The site LocationsModel uses GROUP BY a.id when joining to the categories junction table, but selects non-aggregated columns (title, address, etc.) that are not in the GROUP BY clause. This works on MySQL with ONLY_FULL_GROUP_BY disabled (the default on many hosts) but fails on strict mode.

Error

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column...

Fix

Either:

  1. Add all selected columns to GROUP BY (verbose but correct)
  2. Use a subquery/EXISTS instead of JOIN + GROUP BY
  3. Use ANY_VALUE() wrapper on non-grouped columns

Option 2 (EXISTS subquery for category filtering) is cleanest and avoids GROUP BY entirely.

Priority

P5 — only affects strict MySQL configurations, but should be fixed for compatibility.

## Summary The site `LocationsModel` uses `GROUP BY a.id` when joining to the categories junction table, but selects non-aggregated columns (title, address, etc.) that are not in the GROUP BY clause. This works on MySQL with `ONLY_FULL_GROUP_BY` disabled (the default on many hosts) but fails on strict mode. ## Error ``` Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column... ``` ## Fix Either: 1. Add all selected columns to GROUP BY (verbose but correct) 2. Use a subquery/EXISTS instead of JOIN + GROUP BY 3. Use `ANY_VALUE()` wrapper on non-grouped columns Option 2 (EXISTS subquery for category filtering) is cleanest and avoids GROUP BY entirely. ## Priority P5 — only affects strict MySQL configurations, but should be fixed for compatibility.
Author
Owner

Branch created: feature/59-bug-group-by-fails-on-strict-mysql-only-

git fetch origin
git checkout feature/59-bug-group-by-fails-on-strict-mysql-only-
Branch created: [`feature/59-bug-group-by-fails-on-strict-mysql-only-`](https://git.mokoconsulting.tech/MokoConsulting/MokoSuiteStoreLocator/src/branch/feature/59-bug-group-by-fails-on-strict-mysql-only-) ```bash git fetch origin git checkout feature/59-bug-group-by-fails-on-strict-mysql-only- ```
Author
Owner

Fixed in site/src/Model/LocationsModel.php:

  • Replaced INNER JOIN + implicit GROUP BY with EXISTS subquery for category filtering
  • No GROUP BY needed — each location appears once regardless of how many categories match
  • Compatible with ONLY_FULL_GROUP_BY strict SQL mode
Fixed in `site/src/Model/LocationsModel.php`: - Replaced `INNER JOIN` + implicit GROUP BY with `EXISTS` subquery for category filtering - No GROUP BY needed — each location appears once regardless of how many categories match - Compatible with `ONLY_FULL_GROUP_BY` strict SQL mode
Sign in to join this conversation.