mysql - Determine total amount of top result returned -



mysql - Determine total amount of top result returned -

i determine 2 things single query:

most prevalent column in table the amount of times such column located upon querying table

example table:

user_id some_field 1 info 2 info 1 info

the above homecoming user_id # 1 beingness prevalent in table, , homecoming (2) total amount of times located in table.

i have done research , came across 2 types of queries.

group user_id order count(*) desc sum

the problem can't figure out how utilize these 2 queries in conjunction 1 another. example, consider next query returns prevalent column.

$top_user = "select user_id table_name grouping user_id order count(*) desc";

the above query returns "1" based on illustration table shown above. now, able homecoming "2" total amount of times user_id (1) found in table.

is chance possible?

thanks,

evan

you can include count(*) in select list:

select user_id, count(*) totaltimes table_name grouping user_id order count(*) desc;

if want first one:

select user_id, count(*) totaltimes table_name grouping user_id order count(*) desc limit 1;

mysql sql-order-by sum

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -