___________________________
referrer_id | int(11) |
---------------------------
practice_name|varchar(256)|
___________________________
contact_name |varchar(256)|
---------------------------
address |varchar(256)|
---------------------------
city |varchar(256)|
---------------------------
county |varchar(256)|
---------------------------
postcode |varchar(256)|
---------------------------
contact_num |varchar(256)|
---------------------------
creator_id |int(11) |
$sql = "SELECT * FROM recipient
WHERE practice_name LIKE '%dental%'
OR contact_name LIKE '%couchman%'
AND creator_id = '1219676200'";
我希望查询能够找到练习名称包含' dental'或者contact_name包含' couchman'但仅当creator_id = 1219676200但查询返回满足前两个条件之一的所有行时,无论creator_id如何。
为什么查询忽略了最后一个条件?
答案 0 :(得分:2)
您可能希望使用下面的()
对条件进行分组,因为AND
的优先级高于OR
SELECT * FROM recipient
WHERE (practice_name LIKE '%dental%'
OR contact_name LIKE '%couchman%' )
AND creator_id = '1219676200'