![]() ![]() ![]() ON DUPLICATE KEY UPDATE value=VALUES(value), reading=NOW() The 'bazinga' trick above allows to delete any rows that might have been unwittingly inserted because their id was not present (in other scenarios you might want the inserted rows to stay, though).įor example, a periodic update from a set of gathered sensors, but some sensors might not have been transmitted: INSERT INTO monitor (id, value) ON DUPLICATE KEY SET posx=VALUES(posx), posy=VALUES(posy) In MySQL I think you could do this more easily with a multiple INSERT ON DUPLICATE KEY UPDATE, assuming that id is a primary key keeping in mind that nonexistent conditions ("id = 777" with no 777) will get inserted in the table and maybe cause an error if, for example, other required columns (declared NOT NULL) aren't specified in the query: INSERT INTO tbl (id, posx, posy, bazinga) ![]() If, for example, arrayX and arrayY contain the following values: arrayX = " Īnother way: ON DUPLICATE KEY UPDATE (MySQL) SQL query pseudocode: UPDATE myTable SET posX = posY = and are arrays which store new values for the posX and posY fields. If I know the value of id for each row, and the number of rows, can I perform a single SQL query to update all of the posX and posY fields with different values according to the id? The number of rows changes constantly (might increase or decrease). I have a SQLite database with table myTable and columns id, posX, posY. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |