UPDATE `main` SET `added`='0' WHERE `id`=(SELECT * FROM `main` WHERE `added_2`='0') 

It is necessary that everywhere where added_2 is 0 that added also equal to 0

  • Deploy the problem wider. Show the structure of the tables. - Vladimir Glinskikh

2 answers 2

 UPDATE `main` SET `added`='0' WHERE `added_2`='0' 
  • you have all the search for added_2, even though it is an index, although not an index - splash58
  • 3
    @fonjeekay You first check, and then say that it will not work. For so it is simply obliged to work. Search in tables does not depend on the primary key. The primary is responsible only for the uniqueness of the id and the ability to build forms on it And due to the fact that the primary is implemented by the index - it accelerates the sample for this field. But since you still have a selection for added_2, then the index will not be used (unless you build it separately for this field of course) - Mike
 UPDATE `main` SET `added`='0' WHERE `id` in (SELECT id FROM `main` WHERE `added_2`='0')