I want to update multiple columns using a single query in MySql with some condition that is valid across all colums.
I have around 25 databases with the same table structure in them. I need to update a field named Status across all databases for a particular url using a single query using phpMyAdmin.
Right now I am using this query. (I need to set status=2 in table1 in all of these databases where the url is 'www.google.com')
UPDATE `database1`.`table1` as p1,
`database2`.`table1` as p2 ,
`database3`.`table1` as p3
SET p1.`STATUS` = 2,
p2.`STATUS`= 2,
p3.`STATUS`= 2
WHERE p1.url='www.google.com' and
p1.url=p2.url=p3.url
But it is updating data in all rows not only url='www.google.com'. It is updating status=2 in 'www.yahoo.com' also.
Please help me to solve this.
This is what you want:
and your didn’t work becouse of
p1.url=p2.url=p3.urlthats evaluated as
p1.url=(p2.url=p3.url)where
(p2.url=p3.url)=> FALSE for all that didn’t match,and then we end up with
p1.url=FALSEcomparing
p1.url=FALSE=> comparing a string with an boolean,converting the string to an integer gives 0 for non numeric string,
and converting boolean FALSE to integer gives also 0, so
p1.url=FALSEso
p1.url=p2.url=p3.urlis the same asNOT p2.url=p3.urlso your code update all rows where there exists a p2.url thats not equal to all p3.urls