Considering the following relation movie {country,major_genre,production_year, run_time, title
, I'd like to list all countries except Spain, the movies produced in that country, provided there are at least two of them.
I wrote two queries and they somehow produced different results. It seems that the first one is correct, but it seems to me that they are equal. I am learning SQL. Can someone please help to explain the differences? Thanks for your help!
The first one:
SELECT m1.country, m1.production_year, m1.title
FROM movie m1
WHERE m1.country <> "Spain"
AND m1.country
IN (
SELECT m2.country
FROM movie m2
GROUP BY m2.country //select only the ones with at least 2 movies
HAVING COUNT( * ) >=2
)
ORDER BY m1.country ASC , m1.production_year DESC
And the second one:
SELECT m1.country, m1.production_year, m1.title
FROM movie m1
WHERE m1.country <> "Spain"
GROUP BY m1.country
HAVING COUNT( * ) >=2 //the country selected should have count of at least 2 rows
ORDER BY m1.country ASC , m1.production_year DESC