I am having following scenario: I have a table lets say X where fields are
-------------------------
| City | Country |
------------------------|
| Melbourne | Australia |
| Phoenix | USA |
| Manchester| USA |
| Manchester| UK |
| Phoenix | USA |
| Pune | India |
------------------------
I am trying to update city column only when city are same and country are different. I have tried doing
UPDATE X SET (
City) = CONCAT(CITY,COUNTRY) WHERE = ?
What should be where clause?
EDIT:
Output should look like
------------------------------
| City | Country |
-----------------------------|
| Melbourne | Australia |
| Phoenix | USA |
| Manchester, USA| USA |
| Manchester, UK | UK |
| Phoenix | USA |
| Pune | India |
------------------------------
this sets City name to
CONCAT(X.city, ', ', X.Country)only where the same City name exists in multiple countries.EDIT: i think i prefer this other version:
I’m using all these strange joins because MySql doesn’t allow you to update a table if you are referencing it in a subquery.