Forum Moderators: open
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause
Here's the initial query that returns duplicates:
SELECT SUM(field1) as sales,SUM(field2) as cost, AVG(field3) as avgLength FROM table WHERE field4='$field4'
Here's some sample data:
field1 field2 field3 field4
100 10 5 something
110 15 3 something
50 5 5 somethingelse
Here's some sample output:
something 210 25 8
something 210 25 8
something else 50 5 5
On the sample output, it looks like you have field4, which is not being returned in your example query. If you do need to have it returned, you'd want to do something like this:
SELECT field4, SUM(field1) as sales, sum(field2) as cost, avg(field3) as avgLength FROM table WHERE field4='something' GROUP BY field4;
Chad