SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Mr Jojo's Avatar
    Join Date
    May 2007
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select the most frequent value

    I have a table like this:




    Where you see the numbers 1 and 2 in the table is the "user_id", and i want him to tell me what's the user id that has more rows.

    In the picture you see that number one appears more times than number two.
    So sql would assume that the user number one has more rows than number two, so in a TOP 5 list of who has more rows, number one would be in first place!

    How can i tell sql to see which number/string/value appears/exists with more frequency?

    Thanks!

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    $sql = "SELECT user_id,COUNT(user_id) AS TotalUser from your table GROUP BY user_id ORDER BY TotalUser DESC LIMIT 0,1;";
    $res = mysql_query($sql) or die(mysql_error());
    $userid = mysql_result($res, 0, "user_id");
    $highesthit = mysql_result($res, 0, "TotalUser");
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •