Re: Combining 2 queries into 1?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Kim Steinhaug" <kim@xxxxxxxxxxxxx> wrote in message
news:20040530212115.41807.qmail@xxxxxxxxxxxxxxx
> After crawling through the MySql reference I finally found the function I
> was
> looking for, the sollution for combining theese two queries would be :
>
> SELECT count(  *  )  AS online_anonymous, sum( sign( uid )  )  AS
> online_members
> FROM  `database`
>
> I also benchmarked this and the performance went just as I hoped, I run a
> series of x200 and x500 queries within a loop and took the time. Tests are
> done
> at the live system on the production server som Im pleased with the
result,
>
> 200x Test 1 in 0.2965 sekunder, 2x queries.
> 200x Test 2 in 0.1633 sekunder, combo query.
> 500x Test 1 in 0.8041 sekunder, 2x queries.
> 500x Test 2 in 0.3949 sekunder, combo query.

At first for improving performance you should use indices :)

Another solution may be such as:

select count(*) as count, sign(length(uid)) as is_members from table group
by sign(length(uid));

it will return records such as:

count | is_members
--------------
N | 1 (true)
M | 0 (false)

WBR, Wicked

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux