mysql - Can I use ON DUPLICATE KEY UPDATE for multiple fields? -



mysql - Can I use ON DUPLICATE KEY UPDATE for multiple fields? -

i have sql insert statement looks this?

$sql = "insert profile_answers (user_id, profile_id, question_id, question_answer, timestamp) values ($user_id, $profile_id, {$i}, $answer, now())";

this called 3 times, each time altering question id user_id , profile_id same. possible prevent duplicate entries using 'on duplicate key update first looking @ first 2 fields (user_id, profile_id)?

a entry in db this:

user_id profile_id question_id 5 7 1 5 7 2 5 7 3

is possible prevent sec insert of ( 5, 7, 1) example?

alter table profile_answers add together unique index(user_id, profile_id, question_id);

this prevent inserting same values twice these columns.

mysql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -