Re: Counting Number of Instances in a One2Many Relationships
| From: | Paul Burney | Date: | Tue, 24 Jul 2001 03:23:27 +0000 |
| Subject: | Re: Counting Number of Instances in a One2Many Relationships | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-10694@lists.php.net to get a copy of this message | ||
on 7/23/01 6:53 PM, Mike Gifford at mike@openconcept.on.ca wrote:
> I'd like a simple query to determine how MANY books in a database are released
> by A publisher. This shouldn't be a big deal, but I've looked at a number of
> solutions and am coming up short. MySQL is being accessed via phplib, but I'm
> sure that it's just how I'm expressing the general MySQL query.
Maybe I'm not quite getting it, but how about:
SELECT COUNT(bibID) FROM bookDB WHERE publisherID='$your_publisher_id';
> The bookID & publisherID are both listed in the bookDB. I just want a query
> which will go through the database and return the publisherID and a count of
> the number of books.
You can do a group by to get them all at once:
SELECT COUNT(*) AS book_count, publisherID FROM bookDB GROUP BY publisherID;
Then use your favorite mysql_fetch_*** and access them.
Hope that helps.
Sincerely,
Paul Burney
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Paul Burney
Webmaster && Open Source Developer
UCLA -> GSE&IS -> ETU
(310) 825-8365
<webmaster@gseis.ucla.edu>
<http://www.gseis.ucla.edu/>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++