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

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -