sql 'is not' ( <> ) is not working

前端 未结 2 1369
遇见更好的自我
遇见更好的自我 2021-01-24 15:29

I have no idea what I do wrong... this is my code:

SELECT *
FROM messages
WHERE userId = \"6\"
OR toUserId = \"6\"
OR toAll = \"1\"
AND id <> \"4\"
ORDER          


        
相关标签:
2条回答
  • 2021-01-24 16:20

    You need to use parenthesis to indicate operator precedence:

    WHERE (
           userId   = "6"
        OR toUserId = "6"
        OR toAll    = "1"
    )
    AND id <> "4"
    
    0 讨论(0)
  • 2021-01-24 16:29

    I think your Query condition should be like this:

    WHERE 
    (userId = "6" OR toUserId = "6" OR toAll = "1") 
    AND (id <> "4")
    

    Your query will be evaluated to:

    WHERE 
      (userId = "6" OR toUserId = "6") OR (toAll = "1" AND id <> "4")
    

    Which is not what you want.

    0 讨论(0)
提交回复
热议问题