SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have this query but MySQL doesn't execute it with this error: Can't group on 'counter'


    SELECT count(entry) AS counter,entry FROM tb GROUP BY counter

    Can anyone tell me what is wrong there? (MySQL version? Mine is 3.22.32) Any workaround? What I want is to sort by the counter
    Thanks
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't group on a field alias
    SELECT count(entry) AS counter,entry FROM tb GROUP BY entry

    should work fine it would be the same result
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It will not return the same result as it will sort by entry (alphabetically) while my goal is the total occurence of that entry
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT count(entry) AS counter,entry FROM tb GROUP BY entry ORDER by counter DESC

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh yeah, that's a good query, Freddy

    I did have a work around for it (using arsort() after executing the query), but guess now I should change

    Thanks a bunch! Too bad Karma is offline...
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •