#1241 - Operand should contain 1 column(s) nested query

426 views Asked by At

i found this error when I enter this command

SELECT *
FROM  Borrowed_Book , User
WHERE User.UserId=Borrowed_Book.UserId  IN (
    SELECT *
    FROM Book , Book_version_info
    WHERE 
        Book_version_info.PublisherID = 1 AND 
        Book.ISBN= Book_version_info.Book_ISBN
);

i cannot find what's the issue here and why i get this error I search on the internet but I don’t find the reason

1

There are 1 answers

0
Yunfei Chen On BEST ANSWER

First of all you should match your columns in the IN function:

WHERE User.UserId=Borrowed_Book.UserId  IN (
    SELECT *
    FROM Book , Book_version_info
    WHERE 
        Book_version_info.PublisherID = 1 AND 
        Book.ISBN= Book_version_info.Book_ISBN
);

SQL does not know what to do with that the columns should be same so try instead:

WHERE User.UserId=Borrowed_Book.UserId  AND User.UserId IN (
    SELECT User.UserId
    FROM Book , Book_version_info, User
    WHERE 
        Book_version_info.PublisherID = 1 AND 
        Book.ISBN= Book_version_info.Book_ISBN
);