我有 2 张 table 。
表 1:tA
+----+--------------------+
| id | url |
+----+--------------------+
| 1 | hxxp://www.aaa.com |
| 2 | hxxp://www.bbb.com |
+----+--------------------+
表 2:待定
+----+-------+--------+----------+
|id | tA_id | cat_id | cat_name |
+----+-------+--------+----------+
| 1 | 1 | 1 | Mobile |
| 2 | 1 | 2 | Other |
| 3 | 2 | 2 | Other |
+----+-------+--------+----------+
预期输出
+----+-------+--------+----------+
| id | tA_id | cat_id | cat_name |
+----+-------+--------+----------+
| 1 | 1 | 1 | Mobile |
| 3 | 2 | 2 | Other |
+----+-------+--------+----------+
mysql代码:
select *
from tA
inner tB
on tA.id = tB.tA_id
where tB.cat_id = 1
or tB.cat_id = 2
Group By tA_id
我的 mysql 代码的结果:
+----+-------+--------+----------+
| id | tA_id | cat_id | cat_name |
+----+-------+--------+----------+
| 1 | 1 | 2 | Other |
| 3 | 2 | 2 | Other |
+----+-------+--------+----------+
我该怎么办?
最佳答案
按 tA_id 删除您的组,因为它将 cat_name Mobile 和其他分组在一起。
如果您需要保留它,请使用ORDER BY tB.cat_id ASC
,我相信它会显示您需要的cat_id 1和2
关于php - MYSQL OR 一列上的两个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25945308/