处理返回多行的mySQL子查询

m r*_*m r 6 mysql

这是我的例子:

select row_x from table_1 where row_y = (select row_a from table_2 where row_b = x)
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,如果子查询返回多行,我的查询需要返回多行.

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

 'select row_x from table_1 where row_y = '<first row from subquery>' or row_y = '<second row from subquery>' etc.
Run Code Online (Sandbox Code Playgroud)

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

Sha*_*ngh 15

您正在寻找IN条款

select row_x from table_1 
 where row_y 
 IN (
     select row_a from table_2 where row_b = x
    )
Run Code Online (Sandbox Code Playgroud)