I need an sql statement that will update if the row exists and insert if the row doesn't exist. I have a table with the following values...
id is (Unique + auto increment)
id | selectedID | userID | question
------------------------------------
1 | 1 | 3 | 10
if the user with userID 3 selects a different selectedID e.g. 2 for question 10 i want the table to update to:
id | selectedID | userID | question
-----------------------------------
1 | 2 | 3 | 10
And if the user with userID 3 selects selectedID 2 again for question 10 i don't want this to insert another row.
If the user with id 3 selects a selectedID for question 11 I want it to insert a new row e.g. 2 for question 11:
id | selectedID | userID | question
-----------------------------------
1 | 2 | 3 | 10
2 | 2 | 3 | 11