In article <[EMAIL PROTECTED]>,
Laszlo Thoth <[EMAIL PROTECTED]> writes:

> I'm trying to create a single UPDATE query to deal with the following problem:
> ==================================================================
> -- I've got two tables:

> CREATE TABLE `banannas` (
>    `owner` varchar(15) NOT NULL default ''
> );

> CREATE TABLE `monkeys` (
>   `name` varchar(15) default NULL,
>   `banannacount` int(4) default NULL
> );

> -- I've got three monkeys:

> INSERT INTO `monkeys` VALUES ('bonzo',NULL),('dunston',NULL),('ham',NULL);

> -- Some of those monkeys have banannas.
> -- Some of those monkeys have more than one bananna.
> -- Some of those monkeys don't have any banannas.

> INSERT INTO `banannas` VALUES ('bonzo'),('bonzo'),('bonzo'),('ham');
> ==================================================================

> I'm trying to write an UPDATE query so that monkeys.banannacount is set to the
> number of banannas each monkey owns.

Why would you want to do that?  bananacount is something you can
calculate with a LEFT JOIN and a GROUP BY, so storing it in the DB
would break normalization.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to