如何在mysql中基于另一个表更新表?

编程入门 行业动态 更新时间:2024-10-22 14:40:00
本文介绍了如何在mysql中基于另一个表更新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有2张桌子作为休假:

i have 2 tables as fallow:

users zip state city 89012 45869 0 .... zips zip state city 89012 NV lv 45869 MI ca ....

我想基于users表中的zip用zips中的state and city更新users: state and city

i would like to update users: state and city with the state and city from zips based on the zip from the users table in an efficient way

users表中的city为空,但state也可以为0或空

the city in users table is empty but the state can also be 0 or empty

有什么想法吗?

谢谢

推荐答案

您是否要批量更新所有现有行?

Are you trying to update all of the existing rows in bulk?

如果是这样,这是进行更新的一种方法:

If so, here's one way to do the update:

update users u inner join zips z on z.zip = u.zip set u.state = z.state, u.city = z.city;

更多推荐

如何在mysql中基于另一个表更新表?

本文发布于:2023-11-22 03:23:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!