If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Pure SQL question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-04, 17:18
Squatrem Squatrem is offline
Registered User
 
Join Date: Oct 2004
Posts: 6
Post 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 ?
Reply With Quote
  #2 (permalink)  
Old 11-16-04, 18:14
Squatrem Squatrem is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On