MySQL Forums
Forum List  »  Newbie

Re: Multiple Counts with Selects
Posted by: Dave Smith
Date: March 16, 2005 11:28AM

Since Count(*) returns a count of the returned rows and different WHERE clauses result in different number of returned rows, I do not know how to combine these counts into a single query. However, you can use UNION to combine multiple queries into a single result set. In this way to get back a table with the results of all your count queries and can process it without re-querying. Here is a simplified example from your code...

SELECT "Member ID not empty", COUNT(*) FROM log_online WHERE ID_member != '' AND $time - time <= $keep_online_time * 60
UNION
SELECT "Member ID empty", COUNT(*) FROM log_online WHERE ID_member = '' AND $time - time <= $keep_online_time * 60;

If you cut and paste this code into mysql you will get back a table of two columns. The first column of each row will contain the text, which is a label for that count.

Dave

Options: ReplyQuote


Subject
Written By
Posted
Re: Multiple Counts with Selects
March 16, 2005 11:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.