512: Subquery returned more than 1 value(子查询返回的值不止一个)
SQL Server含义
在需要单个值的上下文(=、<、>、比较或赋值)中使用的子查询返回了多行。SQL Server 预期得到单个标量值,却遇到了多个值。
原因
本应为比较返回单个值的子查询返回了多行、匹配条件不唯一、缺少过滤条件,或关联查询构造错误。
解决方法
将子查询缩减为单行(如 TOP 1、MAX/MIN 或合适的 GROUP BY)。如果预期有多个值,用 IN 或 EXISTS 代替 =。用 JOIN 改写。调查子查询为何返回多行,并修正过滤/键条件。
同一数据库的其他条目
- 245Conversion failed when converting the value to data type(将值转换为数据类型时失败)
- 515Cannot insert the value NULL into column(不能将值 NULL 插入列)
- 8115Arithmetic overflow error converting expression to data type(将表达式转换为数据类型时发生算术溢出错误)
- 207Invalid column name(列名无效)
- 156Incorrect syntax near the keyword(关键字附近有语法错误)
- 2812Could not find stored procedure(找不到存储过程)
- 8623The query processor ran out of internal resources and could not produce a query plan(查询处理器耗尽了内部资源,无法生成查询计划)