-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

And answer to the question is:

- -----------------------------------------------------------
$subSelectDraft = $db->select()
                     ->from('articles',
                            array('COUNT(*)')
                     ->where('status = 0');
$subSelectReview = $db->select()
                      ->from('articles',
                             array('COUNT(*)')
                      ->where('status = 1');
$subSelectPublished = $db->select()
                         ->from('articles',
                                array('COUNT(*)')
                         ->where('status = 2');

$select = $db->select()
             ->from(new Zend_Db_Expr('DUAL'),
                    array('Draft' => new Zend_Db_Expr('(' . $subSelectDraft . 
')',
                          'Review' => new Zend_Db_Expr('(' .
$subSelectReview . ')',
                          'Published' => new Zend_Db_Expr('(' .
$subSelectPublished . ')',)));
- -----------------------------------------------------------

DUAL is a MySQL dummy table, dunno if it exists in other DB engines as well.

...................................
:  ___   _   ___ ___ ___ _ ___    :
: |   \ /_\ / __| _ \ _ (_)   \   :
: | |) / _ \\__ \  _/   / | |) |  :
: |___/_/:\_\___/_| |_|_\_|___/   :
:........:........................:
: Web    : http://www.dasprids.de :
: E-mail : [email protected]       :
: Jabber : [email protected]     :
: ICQ    : 105677955              :
:........:........................:


Jason Webster schrieb:
> Not that I'm aware of, but....
> 
> Why do you have to use Zend_Db_Select to do this??
> If it's a static query like that, that isn't built procedurally, there's
> nothing wrong with just using the SQL statement.
> 
> On 18/02/2009 10:31 AM, Henry Umansky wrote:
>> Is there an easy way to run the following query using Zend_Db_Select
>> without using joins?
>>
>> SELECT
>> (SELECT Count(*) FROM articles WHERE status=0) AS 'Draft',
>> (SELECT Count(*) FROM articles WHERE status=1) AS 'Review',
>> (SELECT Count(*) FROM articles WHERE status=2) AS 'Published'
>>
>> I just need to get the count according to the record status.
>>
>> -Henry
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmchcEACgkQ0HfT5Ws789CAZACfRa+jeytXlO+DheRqcITvTrif
LFwAn14UfkK8V4SrBnqlCyzfl/KaU8Qz
=tiUO
-----END PGP SIGNATURE-----

Reply via email to