Answer the question
In order to leave comments, you need to log in
How to add or update sql row if element with desired id exists?
How to add (if the element with the desired id does not exist) or update the row (if the element with the desired id exists)?
So the question is more correctly constructed!
In general, it is necessary that if the line with id exists, it is updated, otherwise it is simply added!
1. Does not take into account the case if the line does not exist.
UPDATE `table` SET `block`="234" WHERE `id`="2";
2. I thought that it would be possible to do it with one request, and it also does not take into account if the rows do not narrow
DELETE FROM `table` WHERE `id`='2';
INSERT INTO `table` ('block', `id`) VALUE("234", "2");
Somewhere I feel I have a gap in knowledge, I apologize if the question was raised somewhere, or it's too obvious. (Google didn’t find it, probably I don’t google correctly, I don’t fully understand how this should happen)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question