使用MySQL select查询显示结果不需要的行

时间:2018-05-09 10:28:58

标签: mysql

我正在尝试选择status = Y的行,但MySQL也显示状态= N和Y的所有数据。我想只显示status = Y的数据。

以下是我的以下MySQL查询:

select * from table where status='Y' and keywords like '%cook%' OR category like '%cook%' OR product_name like '%cook%'

如何显示status = Y的数据。

3 个答案:

答案 0 :(得分:0)

您需要使用or

(...)条件进行分组
select * from table 
where status='Y' 
and (keywords like '%cook%' 
or category like '%cook%' 
or product_name like '%cook%')

答案 1 :(得分:0)

尝试以下

select * from table where status='Y' and (keywords like '%cook%' OR category like '%cook%' OR product_name like '%cook%')

答案 2 :(得分:0)

试试这个

SELECT * FROM `table` WHERE 
`status`='Y' AND 
(keywords LIKE '%cook%' OR category LIKE '%cook%' OR product_name LIKE '%cook%')