以下sql server命令中的错误

时间:2014-03-16 07:27:37

标签: sql-server-2008-r2

select rf_id, bname 
from books 
where rf_id not in (select * 
                    from books 
                    where rf_id='" + tocheck + "');

执行时,它引发了以下错误。请帮我解决这个错误。

  

当未使用EXISTS

引入子查询时,只能在选择列表中指定一个表达式

2 个答案:

答案 0 :(得分:1)

IN运算符希望将rf_id与单个列进行比较,因此应该是:

where rf_id not in (select rf_id....

但是,鉴于子查询受到rf_id的限制,您最好将查询更改为:

select rf_id, bname
from books
where rf_id <> '" + tocheck + "'

答案 1 :(得分:0)

使用:

select rf_id, bname 
from books 
where rf_id not in (select rf_id
                    from books 
                    where rf_id='" + tocheck + "')