Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL:如果子查询中存在或不存在多个值,则返回true/false_Mysql_Sql_Database - Fatal编程技术网

Mysql SQL:如果子查询中存在或不存在多个值,则返回true/false

Mysql SQL:如果子查询中存在或不存在多个值,则返回true/false,mysql,sql,database,Mysql,Sql,Database,我有一个表,其中有两列是外键(想想userID(int):orderID(int),例如),我必须知道在一个大查询的where子句中,用户ID是否存在订单2、3、4、5 我需要优化我的数据库 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 (SE

我有一个表,其中有两列是外键(想想userID(int):orderID(int),例如),我必须知道在一个大查询的where子句中,用户ID是否存在订单2、3、4、5

我需要优化我的数据库

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是否存在我的多值列表?我请求的行是仅包含在具有两个外键的表中的关系

我的亲属:


需要知道Convalcatoria_扇区是否与Convalcatorias(id_bdns_Conv)有X关系作为一个难看的答案,您可以这样连接两列

AND (SELECT column1||column2 from mytable) IN (SELECT column1||column2 from table2 WHERE table2.id = table1.myrow)

不是最好的方法,但它可以工作

您可以通过按用户ID和HAVING子句中的条件进行分组来完成:

select userid
from tablename
where orderid in (2,3,4,5)
group by userid
having count(distinct orderid) = 4

这将选择所有的
userid
s,其中存在
orderid
s2、3、,4和5。

能否将您正在使用的实际表格与一些示例数据一起包括在内?是的,请稍等片刻,我不明白您是否添加了示例数据。请在问题中添加示例数据以使其完整。having子句保证每个用户的不同OrderID为4,因为WHERE子句将OrderID限制为2,3,4,5然后这4个是为用户存在的。这并不能解决我的问题,因为我需要将其添加到“where”子句中以选择行或不选择行。您可以将其添加到where子句中,如:
where somecolumn IN()