I want to insert multiple records or update those records if 2 specific column values do not exist in a record. But the 2 values are NOT UNIQUE, so I can not use ON DUPLICATE KEY. I am trying to not use IF...Then statements. It seems to be bad programming practice.

Here is the pseudo code of what I want to accomplish.

INSERT INTO interest_list (user_id, interest_id, details)
  VALUES
  (1, 1,'somestring1'),
  (1, 2, 'somestring2'), 
 ...etc
IF the record exists where (user_id==1 and interest_id==1) or (user_id==1 and interest_id==2)  ... etc THEN (dont insert but rather update)
UPDATE interest_list
    SET details = CASE interest_id
        WHEN 1 THEN 'somestring1'
        WHEN 2 THEN 'somestring2'
...etc
    END
WHERE interest_id IN (1,2...etc) AND user_id=1;

Its fairly complicated to explain, hopefully someone gets my question. I am trying to accomplish this in 1 query.

For instances like this i always suggest using anonymous blocks or stored procedures and you are probably most likely going to need an if statement

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.