MySQL update many-to-many tabel relation -
i have tables , b , a_has_b have fields:
a: id, name
b: id, name
a_has_b: a_id, b_id, background
previously when had not 'background' field in a_has_b, did update delete record in a_has_b , reinsert updated records.
but how can update a_has_b whitout deleteing records should reinsert?
off top of head, think like....
delete a_has_b not exists ( select 1 b b.id=a_has_b.b_id );
(and similar table 'a')
or
delete a_has_b b.id <> (select id b);
Comments
Post a Comment