开发者

how to merge tables using mysql database?

I have two tables suppose table 1 has two columns with short names and full names of USA and another table has only short name.

I want to write a MySQL query to update all short开发者_如何学编程 names of table 2 with a full name in table 1 on matching with short same of table 1

Table 1                   Table 2        after query I want Table 2

C1   C2                    C6                       C6

NY    New York             NY                       New York

NJ    New Jersey           NJ                       New Jersey


Assuming that Table 2 has a STATE field wide enough to support the full state name and that you want to overwrite the short state name with the long state name. On MySQL 5.0 I believe the UPDATE JOIN statement should be written more like this:

UPDATE Table2 INNER JOIN Table1 on Table2.state=Table1.state 
SET Table2.state=Table1.Full_name  

I think this link has the clearest answer http://blog.ookamikun.com/2008/03/mysql-update-with-join.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜