Skip to content
Advertisement

How to solve this specific SQL query? My solution also returns not wanted values

I have three tables in my DB:

  • Film“, which contains details regarding movies
  • Sale“, which contains details regarding theathers where movies are projected
  • Proiezioni“, which contains details regarding projections, with external references to both the previous tables

The problem involves finding the titles of all the movies that were projected in the city of “Pisa” only.

The problem of this solution is that it gives me the movies that were screened only in “Pisa”, but also the (non-requested) movies that weren’t screened at all (not present in the table “Proiezioni“).

You can find the code for tables generation and population (ddl) below.

The expected output is only one row corresponding to the movie title “I Predatori” having “CodFilm = ‘f03’“.


Advertisement

Answer

You should first inner join “film” with “proiezioni“, such that you’ll ensure to get projected films. Then you can exclude all theathers where the film was projected in any city other than “Pisa“, which will output films that were projected in Pisa only.

Check the demo here.

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