MySQL if not exists by two columns update other -
i want insert record if not exists 2 columns, , if exists update column 3, here's query:
insert aktai_islaidos_id (akto_id, islaidos_id, savikaina) select * (select ? a, ? b, ? c) tmp not exists ( select akto_id, islaidos_id, savikaina aktai_islaidos_id akto_id = , islaidos_id = b ) on duplicate key update savikaina = values(c);
now i'm getting error c not exists in fields list, understand why, didn't know how complete query correctly , didn't find examples selects duplicate columns, thanks!
edit: figured out stored procedure:
create procedure update( in akt_id int, in isl_id int, in sav int) begin if (select count(*) aktai_islaidos_id akto_id = akt_id , islaidos_id = isl_id) > 0 begin update aktai_islaidos_id set savikaina = sav akto_id = akt_id , islaidos_id = isl_id; end; else begin insert aktai_islaidos_id (akto_id, islaidos_id, savikaina) values (akt_id, isl_id, sav); end; end if; end
Comments
Post a Comment