Mysql or/and precedence?

后端 未结 4 1960
悲&欢浪女
悲&欢浪女 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:15

    in all SQL servers, AND takes precedence over OR, so just remember to put brackets around your ORs:

    select * from tablename 
    where (display = 1 or display = 2)
     and (content like "%hello world%" 
          or tags like "%hello world%" 
          or title = "%hello world%")
    


    btw (display = 1 or display = 2) is equivalent to display in (1, 2).

提交回复
热议问题