我尝试阅读,但仍然不知道如何处理此请求:
我有一张这样的桌子:
False
我想在id_category 5&8和id_news像id_opinion一样的地方打电话给我,我正在做这句话,但我认为这是不正确的
id_news id_category id_opinion
113 5 152
112 5 152
152 8 0
153 8 0
114 5 153
115 5 153
谢谢
答案 0 :(得分:2)
您需要将OR
用于id_category
,例如:
SELECT *
FROM news
WHERE (id_category = '5' OR id_category='8') AND id_news = id_opinion;
另一种选择是使用IN
,例如:
SELECT *
FROM news
WHERE id_category IN ('5', '8') AND id_news = id_opinion;
答案 1 :(得分:0)
您可以使用IN运算符来过滤ID_category 5和8:
SELECT *
FROM news
WHERE id_category IN ('5', '8') AND id_news = id_opinion;
答案 2 :(得分:0)
这可能有效。
SELECT c.`id_news` as `newsId`,c.id_category as `Category`,c.id_opinion as `opinion`,d.`id_news` as `newsId1`,d.id_category as `Category1`,d.id_opinion as `opinion1`
from news as c
JOIN news as d on c.`id_news` = d.`id_opinion`
where c.id_category in(5,8)