database - Replacing data of one table using another table in Mysql -


i have 2 table follows.

table : city

  city_id  city_name   state_id   1       cachar       1   2       darrang      1   3       nicobar      1   

table 2 : locality

  pincode  address       city 110020   loni          nicobar 110021   debru         cachar 110024   rogar         cachar 110023   akura         nicobar  

in table city have 1430 rows , containing different cities in india. , in table locality each city contains near 100 pincode .

what want do? : want replace each city(column) in table : locality corresponding city_id in table : city .

question : how can ? there fast way ? don't want use programming language i.e. php or java. there procedure, looping in mysql ?

result should looks this:

table 2 : locality

  pincode  address       city 110020   loni            3 110021   debru           1 110024   rogar           1 110023   akura           3  

you can try this.

update locality join city on locality.city = city.city_name set locality.city = city.city_id 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -