Skip to content
Advertisement

Select Titles of All Books Without any Rating

create table books
(
     id int, 
     title varchar(250), 
     year int, 
     author varchar(250)
);

create table reviewers
(
     id int, 
     name varchar(250)
);

create table ratings
(
     reviewer_id int, 
     book_id int, 
     rating int, 
     rating_date date
);

Select titles of all books without any rating

Now so far I have this

SELECT *
FROM Books
INNER JOIN Book.ID ON Reviewer.ID
WHERE Reviews.review = 'NULL'

Advertisement

Answer

In your case the Ratings table serves as a table connecting ´Books´ and ´Reviewers´.

So to check if there are no ratings you can simply:

SELECT b.*
FROM books b
WHERE NOT EXISTS (SELECT book_id FROM ratings r WHERE r.book_id = b.id)

Meaning that this is showing all the books that do not have any rating. PS: You don’t need INNER JOINs, since you don’t need any information from the rating and reviewers table (since there is none).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement