mysql子查询 - 结果不同时满足

时间:2016-07-20 21:11:34

标签: mysql subquery

我对MySQL有以下SQL查询:

SELECT SQL_CALC_FOUND_ROWS objects.objects_no 
FROM objects 
LEFT JOIN finds ON (objects.objects_no = finds.objects_no) 
LEFT JOIN ceramics ON (objects.objects_no = ceramics.objects_no) 
WHERE 1=1 
and (objects.objects_no) in (select DISTINCT objects_no from objects_materials where thesaurus_term_id in (18658)) 
and (objects.objects_no) in (select DISTINCT objects_no from objects_objects where thesaurus_term_id in (24193)) 
GROUP BY objects.objects_no 
ORDER BY objects.objects_no

我没有获得与两个子查询匹配的结果,而是获得与其中一个匹配的结果。有谁知道为什么会这样?

谢谢,桑德罗

2 个答案:

答案 0 :(得分:0)

尝试将条件括起来。

WHERE (
  (1=1) 
  and ((objects.objects_no) in (select DISTINCT objects_no from objects_materials where thesaurus_term_id in (18658)))
  and ((objects.objects_no) in (select DISTINCT objects_no from objects_objects where thesaurus_term_id in (24193)))
)

答案 1 :(得分:0)

感谢您的帮助。它确实工作得很好。在同义词库中的数据中存在问题。 遗憾!!!