开发者

SQL server 2005, syntax error

开发者 https://www.devze.com 2022-12-23 03:08 出处:网络
This line do not work: (the problem is in the last line) SELECT Book_Name FROM Books WHERE (Year, Faculty) = (SELECT Year, 开发者_高级运维Faculty FROM Books WHERE Book_Id = 1112);

This line do not work: (the problem is in the last line)

SELECT Book_Name  
FROM Books  
WHERE (Year, Faculty) = (SELECT Year, 开发者_高级运维Faculty FROM Books WHERE Book_Id = 1112);

How can I fix it?


    SELECT b.Book_Name  
      FROM Books b
INNER JOIN (Select Year, Faculty From Books Where Book_Id = 1112) b2
        ON b.Year = b2.Year and b.Faculty = b2.Faculty

Without Inner Join the alternative is

SELECT b.Book_Name
  FROM Books b
 WHERE Year In (Select Year From Books Where Book_ID = 1112)
   AND Faculty In (Select Faculty From Books Where Book_ID = 1112)

However, if it is homework you should really work this out for yourself :-p


A join is best, but if you can't (because of homework restriction) ,try this:

SELECT
    Book_Name  
    FROM Books  
    WHERE
        Year IN (SELECT Year FROM Books WHERE Book_Id = 1112)
        AND Faculty IN (SELECT Faculty FROM Books WHERE Book_Id = 1112)
0

精彩评论

暂无评论...
验证码 换一张
取 消