gpt4 book ai didi

mysql - 将“OR”用于多个子查询是否最优?

转载 作者:行者123 更新时间:2023-11-29 05:28:17 24 4
gpt4 key购买 nike

我对下面的表格有一个缓慢的询问。

SELECT DISTINCT * FROM table e
WHERE e.eid in (select eid from view1)
OR e.eid in (select eid from view1)
OR e.eid in (select eid from view2)
OR e.eid in (select eid from view3)
OR e.eid in (select eid from view4)
OR e.eid in (select eid from view5)

我是MySQL新手,但是有没有更快的方法来进行这个查询呢?

最佳答案

可能会像这样使用UNION

SELECT DISTINCT * FROM table e
WHERE e.eid IN
(
SELECT eid FROM view1
UNION
SELECT eid FROM view2
UNION
SELECT eid FROM view3
UNION
SELECT eid FROM view4
UNION
SELECT eid FROM view5
)

关于mysql - 将“OR”用于多个子查询是否最优?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17499810/

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