Solved

MySql query question

Posted on 2006-07-18
4
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
ID: 17128289
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
ID: 17128360
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
ID: 17128374
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
ID: 17128961
it works v4.1+ because these versions supports subquery.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cygwin - GNU GPL License 1 56
Hide file extensions in Notepad++ tabs 2 81
Java array 10 86
Data Analysis 7 59
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

737 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