I have two databases, one for holding book records and one for holding loan records.
The SQL below only doesn't work properly. It gives me the results where books have been returned, but not books that haven't been part of a loan.
SELECT Book.BookID, Book.ISBN, Book.Title, Book.AuthorID, Book.SubjectID, Loans.[Returned?]
FROM Book INNER JOIN Loans ON Book.BookID = Loans.BookID
WHERE ((Book.BookID) Not In (SELECT DISTINCT BookID FROM [Loans] WHERE BookID IS NOT NULL)) OR (((Loans.[Returned?])=True))
ORDER BY Book.Title;
What have I done wrong?
EDIT: I want the query to collect books that are currently available, for a report I want to produce. Available books includes books that have been returned and books that haven't been borrowed.
If I understand right, you want all books not in the Loans table and books in the Loans tabled marked as returned. Try this: