있으면 update하고, 없으면 insert 하는 mysql - Insert On Duplicate Key Update 구문에서..

update where, table name을 쓰지 말고, insert 하듯이 사용하면 됨.  

update 때문에 where, table 넣다가 삽질함. 



INSERT INTO template (

 channel_id,

 template_id,

 language,

 description

) VALUES (

 #{channelId},

 #{templateId},

 #{language},

 #{description}

) ON DUPLICATE KEY UPDATE

 description = #{description},

 channel_id = #{channelId}, 

 template_id = #{templateId},

 language= #{language} 






예제


insert into locationtag_scores (tag_name, write_uv) values ('111', 50), ('1111', 3) on duplicate key update tag_name = values(tag_name), read_pv = values(write_uv)



Posted by '김용환'
,