mysql - MySQL 设置更新
问题描述
我有两张桌子,我们称它们为 Pets 和 Owners。两个表都有一个名为 country_id 的列,无论出于何种原因,沿途的某个地方都有 Pets.Country_ID 不等于 Owners.Country_ID(它们应该匹配)。
为了解决这个问题,我运行了以下命令:
UPDATE pets
INNER JOIN owners ON owners.id = pets.owner_id
SET pets.country_id = IF(owners.country_id != pets.country_id,
pets.country_id, owner.country_id)
WHERE pets.country_id != owners.country_id
这个对吗?我已经运行了查询,但我仍然得到不匹配的结果。
解决方案
那是因为您if
完全没有必要的条款是错误的。只需删除它
UPDATE pets
INNER JOIN owners ON owners.id = pets.owner_id
SET pets.country_id = owners.country_id
WHERE pets.country_id != owners.country_id
推荐阅读
- python - 从 Python 调用 C DLL 函数时出错
- regex - Notepad++ 正则压制,正则查找和替换
- gnuplot - Gnuplot:类似示波器的线条样式?
- javascript - 在 html 内容中显示 html 标签,在 html 中显示 html 代码片段
- r - 带有传单的交互式等值线图不准确地映射数据
- python - 如何将 pd.dataframe 列表导入现有 excel 文件的末尾而不覆盖它
- git - 当重命名文件并使用旧名称创建新文件时,什么工作流程可以缓解 git 合并冲突?
- windows - 尝试设置 Windows Jenkins slave,但找不到可用的“Windows Slave”插件
- html - 我正在尝试制作具有两种不同颜色的警报框。前任。包含图片
- c++ - 线程消息或更好:访问“大师班”中其他班级的成员