Answer the question
In order to leave comments, you need to log in
How to update multiple rows with one MS SQL query?
Hello! There is a table with two rows:
I need to update either one row or both at the same time, and in each case the Lat and Lng fields are updated together. Wrote a request:
INSERT INTO MyGMap (id, Lat, Lng) VALUES (1,'1','2'), (2,'3','4') ON DUPLICATE KEY UPDATE id = VALUES(id), Lat=VALUES(Lat), Lng=VALUES(Lng)
Answer the question
In order to leave comments, you need to log in
UPDATE Markers
SET Lat = CASE ID WHEN 1 THEN '1' WHEN 2 THEN '3' END,
Lng = CASE ID WHEN 1 THEN '2' WHEN 2 THEN '4' END
WHERE ID IN (1, 2)
Update?
UPDATE MyGMap
SET Lat = '1', Lng = '2'
WHERE Id IN (1, 2);
INSERT INTO MyGMap (Lat, Lng)
VALUES ('1', '2'), ('3', '4');
UPDATE MyGMap as row_1 INNER JOIN MyGMap as row_2
ON
row_1.id = 1 AND
row_2.id = 2
SET
row_1.Lat = '1',
row_1.Lng = '2',
row_2.Lat = '3',
row_3.Lng = '4';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question