Group By and Order By

I am fairly new to SQL and seem to be stuck... I would greatly appreciate any help.  I am trying to write an SQL statement that will tell me what text appears most often in my data.  For example, if I have

Ice Cream
Cookie
Cake
Ice Cream
Muffin

I would like to get 'Ice Cream'

Here's what I have come up with...

"SELECT CC as Complaint, COUNT(CC) AS Total from Data WHERE XYZ GROUP BY CC", which returns

Cake             1
Cookie          1
Ice Cream     2
Muffin           1

I was thinking if I could at least order the 'Total' column I could just always grab the top result, but I cannot seem to get the 'Order By' function to work with the field.  Any idea how to make this work or another way to get the result I am looking for?  Thanks!
jmoran18251Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you where close:
SELECT CC as Complaint, COUNT(*) AS Total from Data WHERE XYZ GROUP BY CC ORDER BY COUNT(*) DESC "

Open in new window

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
with mysql, to get only the "top winner":

SELECT CC as Complaint, COUNT(*) AS Total from Data WHERE XYZ GROUP BY CC ORDER BY COUNT(*) DESC LIMIT 1 "

Open in new window

0
 
jmoran18251Author Commented:
I figured I had to be in the ballpark, but I just couldn't quite get there.  Thank you!  That was killing me!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.