GROUP BY and COUNT(*)

My SQL is working on my web server:

I can’t get it to work in Wappler:

What to do?
Thanks,
Trolle

Hi.
MySQL group by functions work a bit weird in older versions.
I think only in the very latest version they changed the behaviour to work like other SQL providers - such that all columns not in an aggregate function should be part of the group by clause.
Earlier, there was no such restriction and MySQL would just figure it out on its own.

Usually, the version you run on your PhpMyAdmin and the version in Wappler are same, so I am not entirely sure why its running there but not here - could be a driver issue?!

As for a solution, you need to put your three columns id, year_udv, status used in select clause in the group by clause. Right now, only status is mentioned in group by.

Hi sid
Thanks for your reply.
Result should be:

I changed SQL in relation to your suggestion, but it gives an incorrect result:

Other suggestions?
Thanks,
Trolle

If you ORDER BY status you might find it works

Correction
It looks like you have multiple udv_id for each status. Is it just a count of each status you want or does it need to show the uv_id/year information too?

If you just want a count of each status, remove the other columns from the query so the status and count are the only ones left.

Actually, the second result is correct. Since udv_id is different, it is correctly being grouped.
In the first query, the result is technically incorrect since udv_id = 50 is not the only status 12 value.

You will have to get rid of udv_id in select & group by if you want the status to appear only once.

Done!
Thanks,
Trolle

1 Like