I want to update a row if it exists in the table else insert it in SQLite in single query. From SQLite documentation I found out that we can use REPLACE
command for achieving this.
I want to know how to use REPLACE
if there are two or more conditions:
Example:
If I have table TABLE1
with following records:
Name Type InitialValue FinalValue
A 1 20 40
B 2 23 50
A 3 40 60
C 3 54 70
Here Combination of Name
and Type
will be unique.
I want to set initialvalue = 50
and finalvalue = 90
where name = A
and Type = 3
if it exists, else insert it.
I am using this command but it's giving this error:
REPLACE INTO table1 (Name,Type,InitialValue,FinalValue) VALUES ('A',3,50,90 ) WHERE Name='A' AND Type = 3 ;
Error is:
near "WHERE": syntax error Unable to execute statement
How can I achieve my objective? Please help.