coopster - 2:31 pm on Feb 23, 2011 (gmt 0)
Can you view the error log? Because you have a syntax error there. You are missing a comma to separate your product_img column from your COUNT(*) column.
Also, when there is a GROUP BY clause, there are certain rules that apply for grouping columns. One of those rules is "The Single-Value Rule" -- every column named in the SELECT list must also be a grouping column unless it is an argument for one of the set functions. MySQL extends standard SQL by allowing you to use columns or calculations in a SELECT list that don't appear in a GROUP BY clause. The MySQL docs once warned not to use this feature unless the columns you omit from the GROUP BY clause are not unique in the group because you will get unpredictable results. Times may have changed, but I believe it is still good practice to write standard SQL queries.
Next, you may need to use the aggregate function in your HAVING clause too, depending on what mode your MySQL server is running. I updated your query to show you what I mean:
COUNT(id) AS total
HAVING COUNT(id) > 1
Finally, if the updated query still times out, try running it in chunks by adding a LIMIT clause.
By the way, this is only going to work if the combination of id/product_img are duplicates. Meaning, if your product_img is the "product" to which you are referring and it may be different than the identifier in the same record, you are not going to get your expected results.