A mySQL query needed

Discussion in 'PHP' started by KingCobra, May 16, 2009.

  1. #1
    I have a table like this:

    field1
    -----
    A
    A
    B
    C
    D
    D
    D
    E

    I want to make a query to produce a result like this:


    A 2
    B 1
    C 1
    D 3
    E 1

    that means I want to DISTRINCT field1 and count total row for particular letter.
    What will be the query?
     
    KingCobra, May 16, 2009 IP
  2. sw0rdfi5h

    sw0rdfi5h Peon

    Messages:
    4
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    select field1, count(field1) as totals from table1 group by field1;
    
    PHP:
     
    sw0rdfi5h, May 16, 2009 IP
  3. KingCobra

    KingCobra Well-Known Member

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    sw0rdfi5h ,

    Thank You
     
    KingCobra, May 16, 2009 IP