How work this insert and update with if statement query in mysql -


select ifnull(post.id ,insert post(pdate,body) values (1,'a') ,update post set body='update',pdate=2 ) post body='a' , pdate=1 

you can try create stored procedure this:

create procedure `myproc` begin if exists (select post.id post body='a' , pdate=1) update post set body='update',pdate=2; else insert post(pdate,body) values (1,'a'); end if; end // 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -