Jump to content

help with subquery


fperez55

Recommended Posts

HI- I'm having trouble getting the results I need from an sql query. I believe I can accomplish my task with a subquery however I can't get it to work. I have a table of book titles and a one to many table of books read (that holds many people via ID and the book via ID they read). Now I need to get a list of books left to read by a particular person from my join. So the query starts with a join between the books table and the books read table to get the book titles. I use a left join to get all the book titles even if they haven't been read. However I need it to filter out the books that the particular person has read and leave me with a list of books left to be read by the particular person. Since I'm using a join I need it to ignore the records of the other people so that it will include does books in the results while excluding the books that the particular person has read.


SELECT books.bookID, books.Year, books.bookTitle, bookToread.userID, book_genre_list.Genre AS bookGenreID
FROM (
(
(
(
books
LEFT JOIN bookToread ON bookToread.bookID = books.bookID
)
LEFT JOIN book_genre_list ON books.bookGenreID = book_genre_list.GenreID
)

WHERE (
bookToread.userID IS NULL
OR bookToread.userID NOT
IN (

SELECT bookToread.userID
FROM bookToread
WHERE userID =3
)
)
This is what I've been trying. However it excludes all books read by all users rather that by the user that I need (3).


please advise-frank
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.