Mysql or/and precedence?

后端 未结 4 1944
悲&欢浪女
悲&欢浪女 2020-11-22 15:41

I am wondering how or/and works?

For example if I want to get all rows where display = 1

I can just do WHERE tablename.display = 1

and i

4条回答
  •  [愿得一人]
    2020-11-22 16:03

    You need to use brackets for your multiple OR conditions. And for display = 1 OR display = 2 you can use display IN(1,2). Try this:

    SELECT * FROM tableName
    WHERE display IN (1,2)
    AND (content LIKE "%hello world%" 
    OR tags LIKE "%hello world%" 
    OR title LIKE "%hello world%")
    

    For more info look at MySQL: Operator Precedence

提交回复
热议问题