Scenario
I'm using SQL Server 2005 I have a T-Sql query that has multiple criteria to search on the WHERE clause. I'm certain that I'm doing this in a very inefficient and long way round. How can I ensure that I don't have to manually type out all the criteria? Instead I want to pass in the criteria via a SELECT * clause.
Current Query Code
SELECT * FROM tblBooks
WHERE BookID = 1
OR BookID = 4
OR BookID = 5
OR BookID = 7
OR BookID = 8
OR BookID = 11
OR BookID = 14
Proposed PSEUDO Query Code
SELECT * FROM tblBooks
WHERE BookID = (SELECT BookID FROM tblAuthors WHERE Genre = 'Fiction')
Comments On Code
As you can see from the proposed pseudo code, the idea is to select a list of BookIDs from another query and pass this list of criteria into the actual query itself. How do I go about doing this correctly?
Help greatly appreciated.