作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含两列外键的表(例如 userID(int) : orderID(int)),我必须知道用户 ID 是否存在订单 2、3、4、5,在大型查询的 where 子句中。
我需要优化我的数据库
SELECT table1.myrow FROM table1, table2
WHERE table1.myrow = table2.myrow
AND 1 IN (SELECT myRoww from table2 WHERE table2.id = table1.myrow)
AND 2 IN (SELECT myRoww from table2 WHERE table2.id = table1.myrow)
AND 3 IN (SELECT myRoww from table2 WHERE table2.id = table1.myrow)
我想做这样的事情:
AND (SELECT * from mytable) IN (SELECT myRoww from table2 WHERE table2.id = table1.myrow)
如何确定我的多值列表是否存在某个 ID?我请求的行是仅包含在具有两个外键的表中的关系。
我的关系:
需要知道 CONVOCATORIA_SECTOR 是否与 CONVOCATORIAS(id_bdns_Conv) 有 X 关系
最佳答案
您可以通过按用户 ID 和 HAVING 子句中的条件进行分组来实现:
select userid
from tablename
where orderid in (2,3,4,5)
group by userid
having count(distinct orderid) = 4
这将选择存在 orderid
2、3、4 和 5 的所有 userid
。
关于mysql - SQL:如果子查询中存在或不存在多个值,则返回 true/false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58980223/
我是一名优秀的程序员,十分优秀!