What is the best way to only do an update if it going to update only one
row?


You don't say what database you're using.

The general way is to use a unique key in the WHERE clause.

   UPDATE tablename SET foo=1 WHERE id=123

MySQL also lets you use a LIMIT clause that will either limit the
number of rows affected by the update, or matched by the WHERE clause
depending on the MySQL version.

  UPDATE tablename SET foo=1 WHERE bar=2 LIMIT 1

-robin

The LIMIT clause is perfect but is that standard SQL?
I am using MySQL right now but it will be run on another database eventually.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to