我不明白此查询是如何工作的。我无法理解的MySQL的一些高级功能吗?
select A.id from A where A.id in (select B.id from B where B.id = A.id)
一个不必要的相关子查询,该子查询正在获取所有行,而表A的ID匹配了表B。也可以像
一样编写select id
from A
where id in (select id from B)
(或)使用INNER JOIN
select a.id
from A a
join B b on a.id = b.id;
(或)使用WHERE EXISTS
select a.id
from A a
where exists (select 1 from B where id = a.id);
您看到的是子查询或嵌套查询。内部查询给出了结果数组,然后外部查询使用此数组来过滤A表的行。
整个查询没有意义...
更好的查询将是:
SELECT A.id from A JOIN B ON A.id = B.id;
它仅仅是内在加入
SELECT A.id from A INNER JOIN B ON A.id = B.id;