SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Selecting the value that appears most often in a column?

    I have a table...

    id | tid | uid | priority | status

    ...and would like to query it on the uid column to retrieve the uid that appears most frequently in that column. The table is indexed on uid.

    The table size may become immense, so overSELECTing data and figuring it out in PHP will be too pricey.

    What's the speedy way to get this done?

    Thanks,

    Cranjled

  2. #2
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I should add... this is what I've tweaked the query down to... good approach or?

    Code:
    SELECT myField, count(*)
    AS totalRecords
    FROM table
    GROUP BY myField
    ORDER BY totalRecords 
    DESC 
    LIMIT 1;


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
  •