gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:15:19 24 4
gpt4 key购买 nike

我有以下针对 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

我得到的不是匹配两个子查询的结果,而是匹配一个或另一个的结果。有谁知道这是为什么?

谢谢桑德罗

最佳答案

尝试将条件括起来。

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)))
)

关于mysql 子查询 - 结果不同时满足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38490918/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com