(
Select Movie_Name
From Theatres Inner Join Movies
On Theatre_Movie_ID = Movie_ID AND Showing_Time = '9:00PM'
)
INTERSECT
(
Select Movie_Name
From Movies
Where Duration = '2:20'
)
Asked
Active
Viewed 51 times
1

GSerg
- 76,472
- 17
- 159
- 346

Jacob Berger
- 11
- 2
-
1Remove the parentheses? – GSerg Dec 30 '19 at 22:11
-
2What is the error you get? The parentheses are useless, but shouldn't result in an error – Dec 30 '19 at 22:12
-
2You're already joining to movies in the first query, why not add the criteria to your join? – Jason Goemaat Dec 30 '19 at 22:12
-
What is the motivation for using `intersect`? – Bohemian Dec 31 '19 at 00:32
1 Answers
1
As suggested by @jason-goemaat above. Since there's already a JOIN with Movies we can add a WHERE clause for the Duration:
Select Movie_Name
From Theatres Inner Join Movies
On Theatre_Movie_ID = Movie_ID
Where Movies.Duration = '2:20' AND Theatres.Showing_Time = '9:00PM'

karmakaze
- 34,689
- 1
- 30
- 32
-
Not quite the same semantics as the original. If there are multiple movies of the same name – Martin Smith Dec 31 '19 at 16:53
-
If you want unique movie names add `DISTINCT` as in `Select DISTINCT Movie_Name`... – karmakaze Dec 31 '19 at 16:59
-
That isn't the issue. There are two different movies with the name "Bad Boys" - 1983 and 1985. The query in the question will return the name "Bad Boys" if one of the movies has a duration of '2:20' and the other move is showing in theatres at 9PM. The proposed rewrite won't return it in this case - hence not quite same semantics – Martin Smith Dec 31 '19 at 17:07
-
1Yes right. Looking at the implications I suspect that this is more desirable in a real world scenario than the original output. – karmakaze Dec 31 '19 at 18:12