java - Remove records from table which id does not exist in a list, keep existing and insert those not in the table -
i have been thinking way topic suggests: assume given array list of integers, e.g. 1, 3, 5, , in table following have records existing:
categoryid userid 1 2 2 2 3 2
which categoryid , userid form primary key. , array list given user id = 2, want remove records categoryid not in list, 2. , keep in list, 3, insert not in table yet, i.e. 5. , table after operation looks following:
categoryid userid 1 2 3 2 5 2
is there better way other remove records userid = 2, , insert new records according array list?
thanks lot!
as said, want 2 main operations delete
, insert
. cannot these in 1 query, want @ least 2 queries. in other hand can write sql query delete , insert in smart way deletions done in 1 query (by using or different values) , insertion in 1 batch query.
Comments
Post a Comment