我有这个搜索功能有两列。搜索按钮正在工作,但它包含隐藏的列。我该如何修复SQL?这是我的SQL:
SELECT app_keyword.id, app_keyword.visibility,app_keyword.keyword,application_table.app_name
FROM appwarehouse.APP_KEYWORD
INNER JOIN application_table
ON application_table.id = app_keyword.app_id
WHERE app_name like '%$search%' OR keyword like '%$search%'
AND app_keyword.VISIBILITY != 'hidden';"
继续显示隐藏的列。我该如何解决这个问题?
答案 0 :(得分:1)
此问题是由于逻辑运算符的优先级(AND
优先于OR
)。请尝试以下方法:
WHERE (app_name LIKE '%$search%'
OR keyword LIKE '%$search%')
AND app_keyword.VISIBILITY != 'hidden'
在您的查询中,它将作为
执行WHERE app_name LIKE '%$search%'
OR (keyword LIKE '%$search%'
AND app_keyword.VISIBILITY != 'hidden')