Re: Combining 2 queries into 1?
| From: | Kim Steinhaug | Date: | Sun, 30 May 2004 17:27:52 +0000 |
| Subject: | Re: Combining 2 queries into 1? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34585@lists.php.net to get a copy of this message | ||
And ofcourse, one part I didnt take into the equation,
one complex query doesnt always execute faster than
two fast queries.
So I might as well be sure that the environment is optimized
for the two queries im already having...
I still however would like to know if its possible to join the
two into one.
Thanks in advance.
--
--
Kim Steinhaug
----------------------------------------------------------------------
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
----------------------------------------------------------------------
www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
----------------------------------------------------------------------
"Kim Steinhaug" <kim@steinhaug.com> wrote in message
news:20040530172006.44102.qmail@pb1.pair.com...
> I have theese two queries :
>
> select count(*) as online from online where uid='';
> select count(*) as online from online where uid!='';
>
> Each online user has a uid (UserID), so if their logged
> inn this field will represent their unique uid. If not logged
> in its set to nothing.
>
> To detect how many online users the first query tells me
> all the "anonymous" users and the second gives "members".
>
> Since theese two queries are fired on every page hit, I would
> assume that if I could join theese queries into one I would
> atleast save the mysql for a 50% of the queries.
>
> Ive veeb experimenting on the count(expression) without
> any luck, probably since the server is running v4.0.17-standard
>
> So I wonder - is there any way I could join the above queries
> into one single query? Ofcourse I could easily add another
> field for the database, something like temp which is NULL for
> anonymous and 1 for user if this makes is easier to group the
> the query in some wmart way I havnt figured out at the moment.
>
> --
> --
> Kim Steinhaug
> ----------------------------------------------------------------------
> There are 10 types of people when it comes to binary numbers:
> those who understand them, and those who don't.
> ----------------------------------------------------------------------
> www.steinhaug.com - www.easywebshop.no - www.webkitpro.com
> ----------------------------------------------------------------------