Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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?
0
blacklord
Asked:
blacklord
  • 2
1 Solution
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now