Solved

MySql query question

Posted on 2006-07-18
4
216 Views
Last Modified: 2010-04-17
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
Comment
Question by:blacklord
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
Comment Utility
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
 

Author Comment

by:blacklord
Comment Utility
it worked, thank you. But does this work only on  latest mysql version or work on older versions too. thanks.
0
 
LVL 35

Expert Comment

by:Raynard7
Comment Utility
It should work on v4.x but I have never used 3.x before so I do not know
0
 
LVL 3

Expert Comment

by:cdemir
Comment Utility
it works v4.1+ because these versions supports subquery.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about a problem I had getting the GPS LocationListener working.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now