Jump to content

Insert into record where 2 fields must match


Go to solution Solved by Phi11W,

Recommended Posts

I want to insert (not replace) data into a record that already exists. The user would not know the ID of the record so I have to use a concatenation of 2 fields to get the correct record. This is the sort of thing I want but I know it isn't right.

INSERT INTO table ('field5') values('value1') WHERE ('field1') == 'value2' && ('field2')=='value3';

What's the right way to do this?

  • Solution
18 hours ago, singingsands said:

I want to insert (not replace) data into a record that already exists. 

You INSERT new records.  

You UPDATE existing records.  When you do this, you replace the values that were in that record before you updated it. 
There is no way around this - it's just how databases work. 

What you're attempting to do is an UPDATE: 

UPDATE `table` 
SET field5 = 'value1' 
WHERE field1 = 'value2' 
  AND field2 = 'value3'

Regards, 
   Phill W. 

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.