I have a MySQL associative table (user_category) that stores user preferences for categories. It has a UserId column and a CategoryCode column. If a user was interested in travel categories (trvl) and a free category (free), the entry would be like this.
UserId CategoryCode
1 trvl
1 free
What is the best way to update this entry when a user updates their preferences in a category? I thought the easiest way is just
DELETE FROM user_category WHERE UserId = 1;
INSERT INTO user_category (UserId,CategoryCode) VALUES (1,'catx'),(1,'catx'),(1,'catx')
Where "catx" are the new categories that interest them.
source
share