SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    82
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Order by count of same values

    Hello
    I have table with the following:
    id| name | value

    I would like to show results with PHP of the records with the most same values
    For example:

    1|test|value1
    2|mmimi|value1
    3|mfdmdf|value2

    it will show:

    value1|2
    value2|1

    the number above is the number of records with the same value (value1,value2).
    Owner of uReviews & MovieDB - Movie Database

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT value
         , COUNT(*) AS howmany
      FROM daTable
    GROUP
        BY value
    ORDER
        BY COUNT(*) DESC LIMIT 1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Posts
    82
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    SELECT value
         , COUNT(*) AS howmany
      FROM daTable
    GROUP
        BY value
    ORDER
        BY COUNT(*) DESC LIMIT 1
    Thank you very much, it works great.
    Owner of uReviews & MovieDB - Movie Database


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •