I’m making a webpage for a library and I need to make a list that shows all the books which are not rented within the past year.
At the moment I have a Query that filters on the Rent table, where all the records are of rented books. But can be rented multiple times so a book can show up multiple times in the table. The problem is, when a book isn’t rented to a person for more then a year, but the same book is rented to another person within the past year, it shows still that book because it saw one record fullfilling the conditions. But I need to know which book isn’t rented at all in the past year. Can anyone help me with that?
I changed the real query to an easier to understand query (language difference), so don’t check on bad spelling or simple syntax problems.
My query a.t.m.:
SELECT
Book.BookID,
Book.BoekTitle,
Writer.WriterName
FROM (
(Book INNER JOIN BookWriter ON Book.BookID=BookWriter.BookID)
INNER JOIN Writer ON BookWriter.WriterID=Writer.WriterID
)
INNER JOIN BookRenting ON Book.BookID=BookRenting.BookID
WHERE
BookRenting.RentDate < DATEADD('yyyy', -1, NOW());
I use an MS Access database!
Thanks in advance for helping me!
First, you probably need to take care of the condition where the book has never been rented. This requires an outer join.
This should get you what you want:
And, I meant to add that books can have multiple writers. You will still get duplicates in the output.