Need Help in MySQL Select on Joining 3 Tables

Discussion in 'MySQL' started by anilinkz, Aug 2, 2010.

  1. #1
    I have 3 tables....

    posts
    postid | author | poststatus
    20 | mark | published
    21 | lisa | published
    22 | glen | published
    23 | ace | published
    24 | ace | draft
    25 | mark | published
    26 | mark | published
    27 | lisa | published
    28 | glen | published
    29 | mark | published

    relations
    postid | category
    20 | science
    21 | math
    22 | math
    23 | english
    24 | english
    25 | science
    26 | math
    27 | english
    28 | english
    29 | math



    category
    category | categorystatus
    science | show
    math | show
    english | notshow


    im really having problems with joning 3 tables...

    In my query, i want to list(group) all authors and count all their posts that are in a category in which the category status is "show"

    this is what i've done so far.... (2 tables joined)

    SELECT posts.author, count(*)
    FROM posts
    INNER JOIN relations
    ON posts.postid = relations.postid
    WHERE (posts.poststatus = 'published') AND (posts.author = 'mark ' OR posts.author = 'lisa' OR posts.author = 'glen' OR posts.author = 'ace')
    GROUP BY posts.author


    it counts all posts from all the authors. but still lacks the ability to join the 3rd table in which it can determine if a post is from a category that the status is "show"

    TIA
     
    anilinkz, Aug 2, 2010 IP
  2. gikone

    gikone Member

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #2
    I just tested it... on localhost:
    This query will count posts for each author if the categorystatus has value 'show' and poststatus has value 'published'
     
    Last edited: Aug 3, 2010
    gikone, Aug 3, 2010 IP
  3. anilinkz

    anilinkz Peon

    Messages:
    118
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you. it worked. ^_^
     
    anilinkz, Aug 3, 2010 IP
  4. gikone

    gikone Member

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #4
    you're welcome!
     
    gikone, Aug 3, 2010 IP