Count of quantity of each Surname listed, and possibly sort in order of that?

Discussion in 'PHP' started by pmf123, Sep 17, 2010.

  1. #1
    I have a sort command to put a list of Surnames in order and unique using DISTINCT and ORDER BY.

    How would I get a count of quantity of each Surname listed in my database, and possibly sort in order of that or at least display that number?
     
    pmf123, Sep 17, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    SELECT Surname, COUNT(Surname) AS totSurname FROM yourtablehere GROUP BY Surname ORDER BY COUNT(Surname) DESC; 
    PHP:
     
    plog, Sep 17, 2010 IP
  3. pmf123

    pmf123 Notable Member

    Messages:
    1,449
    Likes Received:
    81
    Best Answers:
    0
    Trophy Points:
    215
    #3
    Thanks, that works like a charm!
     
    pmf123, Sep 17, 2010 IP