+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, MySQL - counting distinct values in Coding and Web Development; In MySQL, how do you generate the query from the table shown? It's something to do with COUNT DISTINCT and ...
  1. #1

    unixman_again's Avatar
    Join Date
    Nov 2011
    Posts
    929
    Thank Post
    35
    Thanked 173 Times in 133 Posts
    Rep Power
    142

    MySQL - counting distinct values

    In MySQL, how do you generate the query from the table shown? It's something to do with COUNT DISTINCT and GROUP BY (I think) but I can get the flippin' thing to work!

    Thanks!

    Code:
    table                          results that I'd like returned                       
    id   uid     course            uid    course     count     
    1    122      1                122     1          2
    2    122      1                122     2          1
    3    122      2                127     1          1
    4    127      1                127     2          2
    5    127      2
    6    127      2

  2. #2


    Join Date
    May 2009
    Posts
    3,388
    Thank Post
    301
    Thanked 915 Times in 683 Posts
    Rep Power
    346
    select uid, course, count(course) from <table> group by uid,course

  3. Thanks to pcstru from:

    unixman_again (17th January 2013)

  4. #3

    unixman_again's Avatar
    Join Date
    Nov 2011
    Posts
    929
    Thank Post
    35
    Thanked 173 Times in 133 Posts
    Rep Power
    142
    Cheers, that was quick! beer-icon.png



SHARE:
+ Post New Thread

Similar Threads

  1. Mysql Update where value = AnyNumber
    By danIT in forum Scripts
    Replies: 3
    Last Post: 11th February 2009, 11:35 PM
  2. MySql Query - Count chracters
    By danIT in forum Scripts
    Replies: 1
    Last Post: 17th October 2008, 03:17 PM
  3. MySQL Network access
    By _Bob_ in forum *nix
    Replies: 5
    Last Post: 6th April 2006, 02:30 PM
  4. Php/MySQL Web Design
    By Adam in forum How do you do....it?
    Replies: 8
    Last Post: 18th July 2005, 05:13 PM
  5. php MySql
    By iking in forum Books and Manuals
    Replies: 0
    Last Post: 11th July 2005, 04:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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