MySQL Forums
Forum List  »  InnoDB

Re: Can insert update a table based on match of one column value?
Posted by: nobody nobody
Date: February 06, 2019 05:35PM

Peter Brawley Wrote:
-------------------------------------------------------
> 3 queries in a transaction, eg in an sproc ...

Yes, I wish I could have a single query, there are so many powerful statements mysql, but I could not find a single statement for simply matching one column for updating or inserting.

I've slightly changed the columns to use a timestamp for updating, I think I can reduce it to 2 queries, but it got syntax error, does mysql support if exists? I thought it should.

if exists(select id from data_table where id = id_value and timestamp < timestamp_now - 86400) update data_table set data = data_value else insert into data_table (id, timestamp, data) values (id_value, timestamp_value, data_value);

Options: ReplyQuote




Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.