當(dāng)前位置:
首頁 >
網(wǎng)站開發(fā) > 正文
用小括號(hào)()包含就可以區(qū)別開。
例如:
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 字符串的數(shù)據(jù),并且 contents 字段模糊查詢包含 good 字符串的數(shù)據(jù),或者contents 字段模糊查詢包含 ok 字符串的數(shù)據(jù)
比如數(shù)據(jù)表數(shù)據(jù)如下:
字段 id --- title --- contents
數(shù)據(jù) 1 --- 11hello22 --- yougoodss
2 --- aaahello333 --- fdffokssfff
3 --- bbbhello666 ---- fffaafdafa1
像上面的數(shù)據(jù)sql語句會(huì)同時(shí)查詢出1、2的數(shù)據(jù)。
就像四則運(yùn)算加上小括號(hào)就有了計(jì)算優(yōu)先原則。