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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -