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
Post a Comment