in reply to INSERT or UPDATE, but only when unique

Check out MySQL's REPLACE command and newer ON DUPLICATE KEY UPDATE syntax.
  • Comment on Re: INSERT or UPDATE, but only when unique

Replies are listed 'Best First'.
Re^2: INSERT or UPDATE, but only when unique
by jbrugger (Parson) on Mar 12, 2005 at 11:06 UTC
    The replace into is a nice thing, but remind that you need an id to check against and it is not cross-database capable.
    So when making an database driven app, that might run on more databases, i'd avoid the use of a not standard sql statement like this one.
    Why don't you just tell the database to create the field so that it only should contain unique values? then just use insert and update (catch the message of the database to see if insert went ok, else use update)