Display category information on article table output

Discussion in 'MySQL' started by lilac2, Feb 23, 2012.

  1. #1
    *edit title: Member information

    Hi all,

    I currently have 2 tables with the following fields

    ARTICLE
    ArticleID
    ArticleTitle
    ArticleText
    MemberID

    Member
    MemberID
    Member info etc

    I am trying to Sort (ORDER BY) by the most active Members, that is, those who have written the most articles

    On the page I am trying to configure it to display

    Member 1 - articles written 1,2,3 etc
    Member 2
    Member 3
    etc. based on the number of article the member has written. In the above example, Member 1 may have written 5, Member 2 may have 2 articles and Member 3 might have 0 - so I am trying to count how many times MemberID appears in the ARTICLE table to get it to sort in this way, but having no such luck! :(

    Any assistance is much appreciated
     
    Last edited: Feb 23, 2012
    lilac2, Feb 23, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Group by memberID, order by count(memberID)

    should work.
     
    Rukbat, Feb 25, 2012 IP
  3. lilac2

    lilac2 Peon

    Messages:
    367
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This does not work, it just reterns the most recent member to join :(
     
    lilac2, Mar 3, 2012 IP
  4. lilac2

    lilac2 Peon

    Messages:
    367
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have the following code working but it only returns the ID NUMBER of the member, not their name (since that's stored in the Member table). Any ideas about how I can list the NAME instead of the ID number? Thanks again.

     
    lilac2, Mar 3, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    Try
    
    SELECT Member.Name, COUNT(Article.MemberID) AS total
    FROM Article, Member
    GROUP BY Member.Name
    ORDER BY Article.total DESC
    
    Code (markup):
     
    Rukbat, Mar 4, 2012 IP