我知道这是一个非常愚蠢的问题,相信我,我尝试了一切。这是我的最后一招。
我正在尝试运行子查询。令人惊讶的是mysql挂起(即使它不是一个大问题)。
我正在尝试运行此查询以返回一个Link_ids列表
select distinct link_id from join_link_object where obj_id = (select group_concat(obj_id) from xalt_object where module_name like '%intel-compilers/2016.0.047%');
+---------+
| link_id |
+---------+
| 153249 |
+---------+
返回的结果不正确。而不是返回link_id查询列表只返回第一个。
我知道使用=
不是一个好主意,我尝试使用IN
,但提示只是挂起并且什么都不返回。
虽然单独运行子查询然后运行主查询及其结果会得到正确的结果(手动验证)。
mysql> select group_concat(obj_id) from xalt_object where module_name like '%intel-compilers/2016.0.047%';
+-------------------------------------------+
| group_concat(obj_id) |
+-------------------------------------------+
| 352304,352305,352306,352307,352308,354813 |
+-------------------------------------------+
然后运行主查询 -
mysql> select distinct link_id from join_link_object where obj_id in (352304,352305,352306,352307,352308,354813);
+---------+
| link_id |
+---------+
| 153249 |
| 153467 |
| 153996 |
| 154170 |
| 155077 |
| 155099 |
| 155100 |
+---------+
我甚至尝试过使用EXISTS,但这些查询返回了荒谬的结果(大约156995行) -
select distinct link_id from join_link_object where EXISTS (select obj_id from xalt_object where module_name like '%intel-compilers/2016.0.047%');
请指教!谢谢
答案 0 :(得分:2)
在第一个查询中,您将obj_id
与子查询结果进行比较,当您应该过滤obj_id in
子查询结果时,就像在测试中所做的那样:
select distinct link_id
from join_link_object
where obj_id in (352304,352305,352306,352307,352308,354813);
这里应该是什么:
select distinct link_id
from join_link_object
where obj_id
in (select obj_id from xalt_object where module_name like '%intel-compilers/2016.0.047%');
要提高性能,请尝试以下方法:
SELECT DISTINCT jlo.link_id
FROM join_link_object AS jlo
INNER JOIN xalt_object AS xo
ON (jlo.obj_id = xo.obj_id)
WHERE xo.module_name LIKE '%intel-compilers/2016.0.047%';