List:General Discussion« Previous MessageNext Message »
From:Johan Höök Date:April 20 2007 7:27am
Subject:Re: UPDATE and INSERT in one
View as plain text  
Hi,
what you want to look into is (depending on your version)
either "INSERT ... ON DUPLICATE KEY UPDATE ..." or REPLACE
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html
http://dev.mysql.com/doc/refman/5.0/en/replace.html

/Johan

lists@stripped skrev:
> Hi,
> 
> I want to update a table if it meets some conditions (already exist) and 
> INSERT otherwise?
> 
> Right now I am doing it this way:
> 
> 1. SELECT the record
> 2. If it exist, I UPDATE it
> 3. If it does not exit, I INSERT a new record
> 
> Could this be done in one query? I mean like conditional update/insert?
> 
> /Peter
> 
> 
> --MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    
> http://lists.mysql.com/mysql?unsub=1
> 
> 
> --No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 269.5.5/769 - Release Date: 
> 2007-04-19 17:56
> 
> 

Thread
UPDATE and INSERT in onelists20 Apr
  • Re: UPDATE and INSERT in oneJohan Höök20 Apr
    • INSERT ... ON DUPLICATE KEY UPDATE seems so close and yet so far...Daevid Vincent28 Apr
      • Re: INSERT ... ON DUPLICATE KEY UPDATE seems so close and yet sofar...Philip Hallstrom28 Apr
        • RE: INSERT ... ON DUPLICATE KEY UPDATE seems so close and yet so far...Daevid Vincent30 Apr
  • Re: UPDATE and INSERT in oneDavid Precious20 Apr
Re: UPDATE and INSERT in onewang shuming20 Apr