当前位置: 首页 > 网站开发 > 正文

php SQL语句有and也有or应该怎么写?

妙网小编 发表于2016年8月14日 19:04
用小括号()包含就可以区别开。
例如:
select * from table where title like '%hello%' and (contents like '%good%' or contents like '%ok%')
sql语句where部分解释如下:
title like '%hello%' and (contents like '%good%' or contents like '%ok%')
title 字段模糊查询包含 hello 字符串的数据,并且 contents 字段模糊查询包含 good 字符串的数据,或者contents 字段模糊查询包含 ok 字符串的数据
比如数据表数据如下:
字段 id --- title --- contents
数据 1 --- 11hello22 --- yougoodss
2 --- aaahello333 --- fdffokssfff
3 --- bbbhello666 ---- fffaafdafa1
像上面的数据sql语句会同时查询出1、2的数据。
就像四则运算加上小括号就有了计算优先原则。 
本文标签: 网站制作网站建设网站设计HTMLPHP
本文标题: php SQL语句有and也有or应该怎么写?
本文链接: https://www.mwkj.net/m/?post=611

随机文章推荐 收藏本文

共有2839阅 / 0我要评论
  1. 还没有评论呢,快抢沙发~

发表你的评论吧返回顶部

!评论内容需包含中文

请勾选本项再提交评论