当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - How to delete the rows which are not updated?

问题描述:

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 "},

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

]

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: