In the past I had a query with 2 joins and each join had a count selected in it. Some programmer on another site told me that would not work because of however joins behave where it wouldn't count only the rows from that table, but also returned some other rows from the other join. i don't know... I'm not good at this, I just know what he said and indeed that query did give erroneous results.
So how do I get multiple counts in a query with joins and have them be accurate?
And also does this issue only come up with multiple joins?
What do I do if I have only one join but I need two counts from that joined table? The only thing I have known to do is do a second join on the same table and change the where clause when doing the count, but that would then cause this sisue due to multiple joins again.
In the example from the past I simply got the counts from a different query, but that is not ideal... I put the counts in an associative array and got them back to merge them later o. I may have to do that again, which is not ideal.
MySQL: Two Counts
Started by BASHERS33, May 22 2009 07:35 PM
1 reply to this topic
#1
Posted 22 May 2009 - 07:35 PM
|
|
|
#2
Posted 23 May 2009 - 06:27 AM
Start by looking at what the join creates without COUNT.
You may be able to use a COUNT along with a GROUP BY clause to get a few counts based of various criteria. With two tables, it is extremely likely that you will either need to throw in some DISTINCT options as well.
Ultimately, you may be better off with two distinct queries, however.
You may be able to use a COUNT along with a GROUP BY clause to get a few counts based of various criteria. With two tables, it is extremely likely that you will either need to throw in some DISTINCT options as well.
Ultimately, you may be better off with two distinct queries, however.


Sign In
Create Account


Back to top









