mysql conditional insert -
can have sql insert this?
insert a_has_b (a_id,b_id) values (1,2) if not (select count(a_id) a_has_b a_id = 1 , b_id = 2);
to answer question, do:
insert a_has_b ( a_id, b_id ) select 1, 2 a_has_b a_id = 1 , b_id = 2; however, think looking insert ignore:
insert ignore a_has_b ( a_id, b_id ) values (1, 2); this way ignore if there duplicate rows , have proper primary key on values.
Comments
Post a Comment