我正在尝试选择状态= Y的行,但MySQL也显示状态= N和Y的所有数据。我只想显示状态= Y的数据。
这是我的以下MySQL查询:
select * from table where status='Y' and keywords like '%cook%' OR category like '%cook%' OR product_name like '%cook%'
显示状态= Y的数据可以做什么。
您需要使用(...)
对or
条件进行分组
select * from table
where status='Y'
and (keywords like '%cook%'
or category like '%cook%'
or product_name like '%cook%')
尝试如下
select * from table where status='Y' and (keywords like '%cook%' OR category like '%cook%' OR product_name like '%cook%')
试试这个
SELECT * FROM `table` WHERE
`status`='Y' AND
(keywords LIKE '%cook%' OR category LIKE '%cook%' OR product_name LIKE '%cook%')