How to get the item that has the highest number of occurence in a mysql table -
i have table of products shown below:
id name quantity 1 shoe 2 2 pen 1 3 shoe 1 4 glass 3 5 pen 4 6 shoe 2
i want item occurs more in table , number of rows occupies or how many times repeated in table. in case of above table, shoe
occurs highest number of times i.e. 3 times. need mysql query can permit me (return 3 in above case).
please take performance consideration, since query perform on table having 10 million records. thank you!
select name,count(*) products group name order count(*) desc limit 1
this may work
Comments
Post a Comment