Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    6

    Post Unanswered: Pure SQL question

    I'm not sure it's the right forum to post this question but as I'm working on mysql, I though you could help me.

    I have two tables : A(id_A, name_A) and B(id_B, id_A) and I would like to select each (name_A, id_A) with its number of occurence (0 or more) in table B.
    Something like :
    Code:
    SELECT A.id_A, A.name_A, count(B.id_A)
    FROM A, B
    WHERE A.id_A = B.id_A
    GROUP BY A.id_A, A.name_A
    But, of course, this query doesn't show name_As that have 0 occurence in B....

    Does anybody have a solution ?

  2. #2
    Join Date
    Oct 2004
    Posts
    6

    Solution

    OK, OK, one more time I reply to myself ..
    For others SQL newbies like me that could be interested, the solution is : LEFT JOIN.

    The query looks like :

    SELECT A.id_A, A.name_A, count(B.id_A)
    FROM A
    LEFT JOIN B
    ON A.id_A = B.id_A
    GROUP BY A.id_A, A.name_A

Posting Permissions

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