MySQL子查询返回多行的处理 [英] Handling of mySQL sub-query returning multiple rows

查看:806
本文介绍了MySQL子查询返回多行的处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的例子:

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>' or row_y = '<second row from subquery>' etc.

我该如何做到这一点?谢谢!

How can I make this happen? Thanks!

推荐答案

您正在寻找IN子句

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

这篇关于MySQL子查询返回多行的处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆