Re: Combining 2 queries into 1?

From: Date: Mon, 31 May 2004 08:48:22 +0000
Subject: Re: Combining 2 queries into 1?
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-34589@lists.php.net to get a copy of this message
"Kim Steinhaug" <kim@steinhaug.com> wrote in message news:20040530212115.41807.qmail@pb1.pair.com... > 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

« previous php.db (#34589) next »