Hi Ravi
Standard SQL syntax doesn't provide for that. You could wrap the
whole thing in a transaction, possibly in a stored procedure, but
this would be rather awkward.
However, MySQL has a command called "REPLACE" which I think will do
exactly what you want:
http://dev.mysql.com/doc/refman/5.0/en/replace.html
Good luck!
Douglas Sims
[EMAIL PROTECTED]
On Aug 29, 2006, at 12:08 AM, Ravi Kumar. wrote:
Dear Members,
I wish to insert and update conditionally into a table using a
single SQL
statement. That is if a record already exists in a table, the
statement
should update it, else it should insert it. Probably something like
this:
if (select * from UserPoints where username = 'ravi') then
(update UserPoints set points = points + 5 where username = 'ravi')
else
(insert into UserPoints (username, points) values ('ravi', 0))
end if
I can not do it pragmatically using PHP, because the environment is
highly
concurrent and it may result in a 'race condition' often.
The version of MySQL we are using is 4.1.14-standard-log.
Please reply soon, it is urgent.
Have a nice day!
Thanks and regards,
Ravi.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]