How to display the sum of data from a myqsl row?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Louneworld
    New Member
    • Dec 2009
    • 1

    How to display the sum of data from a myqsl row?

    Hello,

    This is killing me.

    Im trying to SELECT how many times a certain data is posted on my database.

    Example: How many times the word "NYC" was submitted.

    So the SELECT should display:
    NYC - 15
    Meaning the word "NYC" is posted in row "city" 15 times.

    How can I SELECT such a query?

    Thank you soo much.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use COUNT with GROUP BY

    [code=mysql]SELECT city, COUNT(*) FROM table_name
    WHERE city = 'NYC'
    GROUP BY city[/code]

    Comment

    • kovik
      Recognized Expert Top Contributor
      • Jun 2007
      • 1044

      #3
      In order to use this with a third-party application (i.e. PHP), you'll want to give the COUNT(*) an alias.

      Code:
      SELECT `city`, COUNT(*) as `total` FROM ...

      Comment

      Working...