开发者

Handling of mySQL sub-query returning multiple rows

Here is my example:

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

The problem that I am running into is that my query needs to return multiple rows if the subquery returns multiple rows.

Ideally it would translate to something similar to:

 'select row_x from table_1 where row_y = '<first row from subquery>' o开发者_C百科r row_y = '<second row from subquery>' etc.

How can I make this happen? Thanks!


You are looking for IN clause

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


SELECT t1.row_x FROM table_1 t1 JOIN table_2 t2 ON t1.row_y=t2.row_a WHERE t2.row_b = x
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜