MySQL - Where Or?

mysql, sql, where-clause

Solution

You need parenthesis around your `OR` statements to group them together logically.

WHERE sticky !=1
AND belongsto !=12 OR sticky !=1 AND belongsto !=13

should be:

WHERE (sticky !=1 AND belongsto !=12)
OR (sticky !=1 AND belongsto !=13)

or better yet:

 WHERE sticky !=1 AND belongsto NOT IN(12,13)

Problem

I have a MySQL statement where I'm trying to exclude statements depending on where they "belong to" The query goes through, but it still shows the rows that I specifically said where its not equal to? ``` SELECT id, belongsto, title, madeby, sticky, locked, lastpost, posts FROM threads WHERE sticky !=1 AND belongsto !=12 OR sticky !=1 AND belongsto !=13 ORDER BY `threads`.`date` DESC LIMIT 20 ```

Original source