I have a table structure as follows:
Id(PK AI) | DataField1(Varchar) | DataField2(Varchar) | User_Id(int)
1 | abc | xyz | 12
2 | sdj | mnu | 09
3 | yjf | pku | 17
4 | anx | vby | 11
I want to insert or update this table.
Let's say I want to insert data as DataField1='wer', DataField2='try'
where User_Id = 11
, provided that a record with given User_Id
does
not exist. If a record with User_Id=11
exists then update the record.
I want a single query and not multiple queries.
Please keep in mind that User_Id
is not unique. Id
is Primary key with Auto increment so I'm not touching that field.
I want something which is similar to 'on duplicate key update'. To my knowledge, this query has no 'where condition'.