Re: mysql COUNT row results

From: Date: Thu, 23 Jun 2011 06:15:38 +0000
Subject: Re: mysql COUNT row results
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-47865@lists.php.net to get a copy of this message
Hi Ron, On Thursday, June 23, 2011, 6:14:38 AM, you wrote: > Is there a way that > SELECT COUNT(auto_increment) as total_subscribers , email FROM > table > may exist within the same query and provide more than 1 row of > search results? When I run a query like this the COUNT portion of > the result is allowing only 1 to be selected. My desire is to have > the the COUNT result appended to each row. > Thoughts anyone? Ron As you noticed, the aggregate function COUNT() means that you get a table with only one row, so you need to join that table to the one that it aggregates. So something like: SELECT A.total_subscribers, B.email FROM table B, (SELECT COUNT(auto_increment) AS total_subscribers FROM table) AS A Should do the trick. HTH, -- Geoff Lane Cornwall, UK geoff@gjctech.co.uk

« previous php.db (#47865) next »