我有一个这样的帖子表:
----- 帖子 -----
- 编号
- ..等..
- 类别 1
- 类别 2
- 类别 3
这些类别中的任何一个都可以被过滤,我正计划构建 SQL 语句,例如:
SELECT *
FROM posts
WHERE category1='..sth..'
AND category1='..sth..'
OR category1='..sth..'
OR category2='..sth..'
OR category3='..sth..'
AND category3='..sth..'
OR ..."
这是一种不好的做法吗?这会带来性能问题吗?
编辑:我给出的查询中的 AND 和 OR 语句仅作为示例。
最佳答案
试试这个
SELECT * FROM posts
WHERE category1 in ('sth','sth')
OR category2 in ('sth','sth')
OR category3 in ('sth','sth')
.....
关于mysql - 使用 AND & OR 语句对 MySQL 来说是不是太糟糕了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18836607/