mysql一个表内字段的关联

西门呀在吹雪 2012-11-17 01:44:46
mysql中 下边这句话怎么改能成功呢
update category set country=(
select xx.country from (
select * from category where parentid=left(parentid,8) and country=''
)xx
);
[Err] 1242 - Subquery returns more than 1 row
我知道啥意思 就不会修改
这是在一个表内的相同字段关联,因为有的country不是空的 我要把为空的country通过parentid关联起来 然后把country更新。
...全文
328 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
WWWWA 2012-11-19
  • 打赏
  • 举报
回复
贴建表及插入记录的SQL,及要求结果出来看看 update category a , (select * from category where parentid=left(parentid,8) and country='') b set a.country=b.country
ACMAIN_CHM 2012-11-17
  • 打赏
  • 举报
回复
update category set country=( select min(xx.country) from ( select * from category where parentid=left(parentid,8) and country='' )xx );
西门呀在吹雪 2012-11-17
  • 打赏
  • 举报
回复
引用 5 楼 ACMAIN_CHM 的回复:
update category set country in ( select xx.country from ( select * from category where parentid=left(parentid,8) and country='' )xxupdate category set country in ( select xx.country from ( select country from category where parentid=left(parentid,8) and country='' )xx ); [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in ( select xx.country from ( select country from category whe' at line 1 ); ……
不行呢
ACMAIN_CHM 2012-11-17
  • 打赏
  • 举报
回复
update category set country in ( select xx.country from ( select * from category where parentid=left(parentid,8) and country='' )xx );
西门呀在吹雪 2012-11-17
  • 打赏
  • 举报
回复
引用 3 楼 lzd_83 的回复:
---like性能比较低的。 update category A,category B set A.country=B.country where B.parentid=left(A.parentid,8) and B.country='';
因为parentid a的是原来的长度有的是16位有的是8为 b里面都是8位的 要匹配的话 只能用like
Rotel-刘志东 2012-11-17
  • 打赏
  • 举报
回复
---like性能比较低的。 update category A,category B set A.country=B.country where B.parentid=left(A.parentid,8) and B.country='';
西门呀在吹雪 2012-11-17
  • 打赏
  • 举报
回复
引用 1 楼 rucypli 的回复:
update category set country=( select xx.country from ( select * from category where parentid=left(parentid,8) and country='' )xx ); up……
我要是用 like匹配该怎么写呢? where B.parentid like %left(A.parentid,8)%?????
rucypli 2012-11-17
  • 打赏
  • 举报
回复
update category set country=( select xx.country from ( select * from category where parentid=left(parentid,8) and country='' )xx ); update category A,category B set A.country=B.country where B.parentid=left(A.parentid,8) and B.country=''

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧