关于SQL语句的问题

写在查询分析器上的语句:update lzhu set zaiwang = (select zaiwang from kkkkk where kkkkk.haoma=lzhu.haoma)
出现的错误是:Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
请问是何原因?
那1对多的该怎么写呢?重点: 那如何删除一个表中的重复记录呢?

1对多的关联。

就是用多的结果集update一条数据

--补充
这得看你的需求了。
比如
select zaiwang from kkkkk where kkkkk.haoma=lzhu.haoma
出来的是:1,2,3,4.。。。
你想把那条更新进去,这是关键

你可以取最大值做update
update lzhu set zaiwang = (select max(zaiwang) from kkkkk where kkkkk.haoma=lzhu.haoma)
最小值做update
update lzhu set zaiwang = (select min(zaiwang) from kkkkk where kkkkk.haoma=lzhu.haoma)
求和做update
update lzhu set zaiwang = (select sum(zaiwang) from kkkkk where kkkkk.haoma=lzhu.haoma)

删除是个很麻烦的事情,除非记录少手工删
要用sql删免补了要取哪条(最大、最小、求和等等)明确这些
sql才能出来
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-05-02
等同于count(*)
,就是分组的记录总数
------
count(1)的那个1意思就是用一个长值字段1来表示存在一条记录
用哪个数字都可以,这样写在字段很多的情况下能更快
第2个回答  2009-05-25
update lzhu set zaiwang = (select distinct zaiwang from kkkkk where kkkkk.haoma=lzhu.haoma)
如果你的haoma和zaiwang 是1对1关系的话 这样应该可以

--在1对多的情况 据我了解是不能更新的
应该选中其中1条
至于怎么选择就看你自己的需求了
第3个回答  2009-05-25
这样写下试试:
update lzhu set zaiwang = (select top 1 zaiwang from kkkkk where kkkkk.haoma=lzhu.haoma)
第4个回答  2009-05-25
update lzhu set zaiwang in (select zaiwang from kkkkk where kkkkk.haoma=lzhu.haoma)
相似回答