I have this table :

 Id | value


1 | bla bla bla

2 | bla bla

my application receives:

  1. rows with ids to update
  2. new data without ids to insert
  3. if an id doesn't exist I should delete it from the table

for example, when this data is received:


{"Id"=>1 ,"value"=>" value 1 "},



after running the query, the table should contain these rows:

Id | value


1 | value1 , update row

2 | bla bla , this row will be deleted row because I don't receive the id

3 | value 2 , there is a new row, because I got an empty Id

How can I implement this query?


Could you add a TimeStamp column, update that column as a part of your INSERT and UPDATE code. At that point, you could run an additional query to DELETE rows that are "old" based on the TimeStamp column.