与存在的另一个表中的指示选择表中的所有行我有三个表使用MySQL查询
Table a
+-----+-------+
| aid | value |
+-----+-------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
+-----+-------+
Table b
+-----+------+
| bid | name |
+-----+------+
| 1 | A |
| 2 | B |
| 3 | C |
+-----+------+
Table ba (mapping of table a and table b)
+-----+-----+
| bid | aid |
+-----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 3 | 2 |
| 1 | 3 |
| 2 | 3 |
| 2 | 4 |
+-----+-----+
在这些表中我要像
SELECT aid, mapped('true'-if(aid exist in ba) 'false'-otherwise)
FROM a
JOIN b
JOIN ba
WHERE bid=1
查询得到的结果从哪里我可以生成一个列表
(when bid=1)
A-mapped
B-not mapped
C-mapped
D-not mapped
(when bid=2)
A-mapped
B-not mapped
C-mapped
D-mapped
(when bid=3)
A-mapped
B-mapped
C-not mapped
D-not mapped
现在我在一个while循环中生成列表的所有行s的表'a',并在循环内为每个迭代执行查询以检查表'ba'中的存在。
这是行不通的。 –
@TimBiegeleisen它肯定会。 – smozgur
不,它没有。你引用'ba.bid'甚至没有提到你的查询中的表。 –