I was currently solving the Databases exercises on Coursera and encountered a problem.
Problem
You've started a new movie-rating website, and you've been collecting data on reviewers' ratings of various movies. There's not much data yet, but you can still try out some interesting queries. Here's the schema:
Movie ( mID, title, year, director )
Reviewer ( rID, name )
Rating ( rID, mID, stars, ratingDate )
Find the titles of all movies that have no ratings.
Solution 1
SELECT DISTINCT title
FROM Movie, Rating
WHERE Movie.mID NOT IN
(SELECT mID
FROM Rating)
Solution 2
SELECT DISTINCT title
FROM Movie, Rating
WHERE NOT EXISTS(SELECT * FROM Rating
WHERE Rating.mID = Movie.mID)
Solution 3
SELECT title
FROM Movie
WHERE title NOT IN(SELECT title
FROM Movie NATURAL JOIN Rating)
I wanted to know whether this can be optimised because I applied DISTINCT
to make them run.