question

Badmash avatar image
Badmash asked

Noob Stuck at a Basic SQL problem

Hi im a real noob in the SQL world trying to understand the basics. I just got stuck in a problem im trying to solve. I have attached the [database][1] (simple txt file with tables no need of SQL). Now I want to find all years that have a movie that received a rating of 4 or 5, and sort them in increasing order. This is how i tried to do it: SELECT distinct year FROM Movie, Rating WHERE Movie.mID = Rating.mID AND stars=4 or stars=5 ORDER BY year ASC; But It doesnt filter the movies, I get back all of them.Why??? [1]: /storage/temp/1564-database.txt [2]: /storage/temp/1563-database.txt
sqldatabasehelp
database.txt (1.0 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@SQLShark avatar image @SQLShark commented ·
If you're new try using ANSI joins to make your code more readable. FROM Movie INNER JOIN Rating ON Movie.mID = Rating.mID
0 Likes 0 ·

1 Answer

·
Squirrel avatar image
Squirrel answered
add the parenthesis around the stars condition WHERE Movie.mID = Rating.mID AND ( stars=4 or stars=5 )
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Badmash avatar image Badmash commented ·
Thanks Bro, that did the trick!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.