I have a table that stores userSettings. These settings are generated from a setting table with a default value and the user table. If a user has set something (or changed the default), I store in the userSettings table the custom value against the settingID and userID.
I get the settings thanks to help from this SO question Joining 3 MySQL tables in to 1 query
Now what I would like to do is Insert a record if it does not exist or Update if it does.
I know I can use ON DUPLICATE KEY however I would like to test against userID and settingID which are 2 foreign keys, not test against userSettingID which is the primary, auto increment ID of userSettings table. If there is a match Update, if there is no match Insert.
A user might have up to 20 custom settings so I can't set UNIQUE on the userID column.
Thanks