我有三个类别&表中的子类别。 类别(冒险,复兴,美食)和sub_category(空气,气球等)
现在我在查询
下面开火了select * from products where sub_category Like '%Air%' or
sub_category Like '%Land%' and category = 'adventure'
and type = 'experience' and status = 'active'
现在问题是它还获得了category = Rejuvenation的行。因此它应该只得到category = adventure
的结果答案 0 :(得分:4)
您必须使用括号或声明:
select * from products where (sub_category Like '%Air%' or
sub_category Like '%Land%' )and category = 'adventure'
and type = 'experience' and status = 'active'
答案 1 :(得分:0)
AND优先于OR。这就是为什么你的查询返回所有东西,它有像Air这样的子类别。您应该像这样更新您的查询:
select * from products where (sub_category Like '%Air%' or
sub_category Like '%Land%') and category = 'adventure'
and type = 'experience' and status = 'active'