Re: max
| From: | Cody Caughlan | Date: | Thu, 09 Nov 2000 17:20:59 +0000 |
| Subject: | Re: max | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-4337@lists.php.net to get a copy of this message | ||
aggregate functions (max(), count(), etc..) cannot be used sql queries after
the WHERE clause without using the GROUP BY and HAVING clauses. I am sure I
am wrong about the details of this, but more or less thats true. Even under
these conditions, you would think you would be able to do:
$query = "SELECT * FROM TABLE GROUP BY someFieldName HAVING max(ID)";
but when I try it on my mysql db I get an empty set, but that works on
oracle, et al..
I think you have to use 2 queries, one to select the max id and the second to
actually do the update with that id.
If someone else can shed some light on this, I am sure we would both
appreciate it.
/Cody Caughlan
Stacy Hunter wrote:
> Any ideas why the max(Id) aspect of this doesn't work?
>
> mysql_db_query("snx_db1","update Nominations set Comment='$message'
> where
> Id=max(Id)");
>
> how do I use update where max in one statement?
>
> Thanks.
>
> - Stacy
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net