PDA

View Full Version : i need you help



4u
11-09-2004, 04:47 PM
in mysql how can i write "max(count(column_name))" in a query?

dr.p
11-11-2004, 05:49 AM
MySQL doesn't seem to like it when you use MAX(COUNT(column_name)) ... What I would normally do is, if I have a query like:


SELECT DISTINCT field_1, count(field_2) as f2_count FROM the_table

which returns ALL of the field_1 values with counts of field_2, then I would use:


SELECT DISTINCT field_1, count(field_2) as f2_count FROM the_table ORDER BY f2_count DESC LIMIT 1

to return only the highest. Hope that helps. Note that this should be the same thing:


SELECT field_1, count(field_2) as f2_count FROM the_table GROUP BY field_1 ORDER BY f2_count DESC LIMIT 1

godzilla
11-16-2004, 10:37 PM
in mysql how can i write "max(count(column_name))" in a query?

could you please give the full query? The problem is in the fact that count by itself may give a single value as result and thus the use of Max is illogical. Again, please supply the query.