Che
Che

Reputation: 87

error in the following sql server command

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

When executed, it raised the following error. Please help me solve this error.

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS

Upvotes: 0

Views: 28

Answers (2)

MattOpen
MattOpen

Reputation: 824

USE:

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

Upvotes: 0

Matt Eno
Matt Eno

Reputation: 697

The IN operator is expecting to compare rf_id to a single column, so it should be:

where rf_id not in (select rf_id....

However, given that the subquery is being limited by rf_id anyway, you're better off just changing the query to be:

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

Upvotes: 1

Related Questions