2014-03-26 28 views
0

更換一個列的數據由於表:有區別與其他列在MySQL

ID || City_1 || City_2 
===================== 
1 || Beijing || null 
2 || Stockholm || Paris 
3 || Tokyo  || Seoul 
4 || Las Vegas || null 
5 || Moscow || null 

我想有區別地把所有非空列2列1,以便更換相應值,新列1看起來像這樣:

ID || City_1 || City_2 
===================== 
1 || Beijing || null 
2 || Paris  || Paris 
3 || Seoul  || Seoul 
4 || Las Vegas || null 
5 || Moscow || null 

什麼是最好的語法呢?

回答

0

我不知道這是最好的語法,但我會用

UPDATE table SET City_1=City_2 WHERE City_2 IS NOT NULL 
相關問題