MySQL 5.7 → group_by error “ SELECT list is not in GROUP BY clause and contains nonaggregated column” when using Phalcon PHP? Try this. (Part II)

Tony Mucci
Aug 27, 2017 · 1 min read
Ooooh….pretty….

So in my last story, I thought that I actually fixed the problem, instead I apparently put a band-aid on a bullet wound. I was missing one key ingredient to my querey, which is a bit tricky in Phalcon’s ORM because their docs don’t really show that you can do this. Think of it like the hidden Animal Style option at In-N-Out. Even though it’s not on the menu, it still exists and you can have it.

TL; DR ? This is the code that

MyModelNameHere::find(['group_by'=>'MIN(your_column_name_here)']);

So essentially what you can do is actually pass in a valid MySQL function in the value of the array inside your Model’s find method. Essentially, what this is saying is that you want Phalcon to group the results by this “your_column_name_here” column. By adding the MIN MySQL function inside this value, Phalcon will apply this function to your group and satisfys MySQL’s only_full_group_by setting that is enabled by default in MySQL 5.7.

Hope this clarified things a bit more for you.

Happy Coding!

Code Kings

Proramming tips & tricks from professionals

)

Tony Mucci

Written by

Co-Founder of Eklect Enterprises • Founder of My Company Tools • Co-Founder of DREE

Code Kings

Proramming tips & tricks from professionals

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade