开发者

sql - insert record on table2 to table 1 with conditions

开发者 https://www.devze.com 2023-02-07 20:52 出处:网络
I have 2 tables on mysql database what they have in common is they both have a city and state field with both being populated with records.

I have 2 tables on mysql database

what they have in common is they both have a city and state field with both being populated with records.

but table2 has a county field while table 1 has none. Where table2 records covers ALL the states and table1 has 1 particular state.

I need to populate table1 county开发者_开发百科 field upon successfully matching city and state fields.

Please help!


First of all add column "country" in table1, then

update table1 a,table2 b set a.country=b.country where a.city=b.city and a.state=b.state

0

精彩评论

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