2014-10-29 72 views
0

我有兩個表,我想更新從表2到表1的字段。想法?如何sql加入/合併

/*Table 1:*/ 


id | name| adress| type 
--+------+--------+---- 
1 | jill | 1 main | 444 
2 | bill | 2 main | 888 



/*Table 2:*/ 


type_id | type 
--------+------- 
444  | green 
888  | blue 



/******GOAL*****/ 

id | name| adress| type 
--+------+--------+---- 
1 | jill | 1 main | green 
2 | bill | 2 main | blue 

我想用table2/column'type'的內容替換表1 /列'type'的內容。

謝謝大家!

+0

你能解釋一下你試圖讓您想達到的效果是什麼?這看起來像基本的SQL。 – 2014-10-29 20:12:41

回答

0

要更新與案件串

整數值,你有字段爲varchar那麼這應該工作

UPDATE TABLE1 T1 
JOIN TABLE2 T2 
on T1.type = T2.type_id 
set T1.type = T2.type 
+0

太棒了!那樣做了。謝了哥們。 – amico 2014-10-29 20:16:21