Please help me with this SQL query; when I use a GROUP BY clause, I get this error from Mysql:
This is incompatible with sql_mode=only_full_group_by
I want different values on column: B.shopname.
SELECT
A.id,
COUNT(A.id),
A.idShop,
B.shopname
FROM
A
INNER JOIN
B ON A.idShop = B.id
GROUP BY
B.shopname
The
GROUP BYcolumns are incompatible with theSELECTcolumns. Why? The query is trying toSELECTthree unaggregated columns,A.id,A.idShop, andB.shopname. However, theGROUP BYonly includes one of those.The general recommendation is to add all unaggregated columns into the
GROUP BY:But I don't think this will do what you want. I am guessing that the
COUNT()will always be1. I suspect you want:Notes:
A.idis no longer in theSELECT. It is not appropriate because you want to count the values.A.idis everNULL, so counting the non-NULLvalues of the column just clutters the query.COUNT(*)is clearer (although some folks preferCOUNT(1)).GROUP BYkeys all be from the same table because it gives the optimizer more options.