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子查询返回多行的处理_Mysql - Fatal编程技术网

mySQL子查询返回多行的处理

mySQL子查询返回多行的处理,mysql,Mysql,以下是我的例子: select row_x from table_1 where row_y = (select row_a from table_2 where row_b = x) 我遇到的问题是,如果子查询返回多行,我的查询需要返回多行 理想情况下,它将转化为类似于: 'select row_x from table_1 where row_y = '<first row from subquery>' or row_y = '<second row from sub

以下是我的例子:

select row_x from table_1 where row_y = (select row_a from table_2 where row_b = x)
我遇到的问题是,如果子查询返回多行,我的查询需要返回多行

理想情况下,它将转化为类似于:

 'select row_x from table_1 where row_y = '<first row from subquery>' or row_y = '<second row from subquery>' etc.
'从表_1中选择行_x,其中行_y=''或行_y=''等。

我怎样才能做到这一点?谢谢

您要在子句中查找

select row_x from table_1 
 where row_y 
 IN (
     select row_a from table_2 where row_b = x
    )

如果您在(子查询)中执行
第y行怎么办?我相信这会更有效。
SELECT t1.row_x FROM table_1 t1 JOIN table_2 t2 ON t1.row_y=t2.row_a WHERE t2.row_b = x