MySql query question

SELECT *, COUNT(*) AS Total FROM TableA
LEFT OUTER JOIN TableB ON TableA.EntryID = TableB.RelEntryID
GROUP BY TableA.EntryID

This query displays total how many entries match from TableB to TableA as "Total" and it works well but with one problem. If nothing matches, it gives 1 as "Total".

Any ideas?
blacklordAsked:
Who is Participating?
 
Raynard7Commented:
Select
    ta.EntryId,
    (select count(*) from TableB tb where tb.RelEntryID = ta.EntryID)
From
    TableA ta

Will give you 0 if there are no results
0
 
blacklordAuthor Commented:
it worked, thank you. But does this work only on  latest mysql version or work on older versions too. thanks.
0
 
Raynard7Commented:
It should work on v4.x but I have never used 3.x before so I do not know
0
 
cdemirCommented:
it works v4.1+ because these versions supports subquery.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.