This is the query and result without using grouping by: Query without grouping by
SELECT count(T2.id_korisnika) As brojPonuda, CONCAT(T2.ime, ' ', T2.prezime) AS naziv
FROM ponude T1, tblKorisnici T2
WHERE T1.id_korisnika = T2.id_korisnika
And this is the query and result with grouping by: Query with grouping by
SELECT count(T2.id_korisnika) As brojPonuda, CONCAT(T2.ime, ' ', T2.prezime) AS naziv
FROM ponude T1, tblKorisnici T2
WHERE T1.id_korisnika = T2.id_korisnika
Group by naziv
My question is why are they opposite of what's supposed to happen? Isn't group by supposed to group multiple rows with same values and produce a result of an aggregate function alongside the grouped value? So why in this case it's doing the opposite of that? When I don't use group by it actually gets automatically grouped by and if I use it I get a weird result where the values are separated, also I don't understand why in some rows there is a 2 and all the others are a 1
Update: it seems to work when I replace the concat and the "naziv" column with id_korisnika. So maybe mysql can't group properly with strings?
Here is the data in the database: