MySQL 是否能够通过一个查询返回多个结果集?
我从过程中成功执行了以下内容(返回两个单独的结果集),但在将其作为基本查询执行时无法执行相同的操作。
SELECT * FROM persons;
SELECT * FROM addresses;
可能的?语法是什么?
编辑:
我正在使用 Ruby 的 DBI 库:
dbh.query("SELECT * FROM persons; SELECT * FROM addresses;")
I have the following (returning two separate result sets) being successfully executed from a proc but cannot do the same when executing this as a basic query.
SELECT * FROM persons;
SELECT * FROM addresses;
Possible? What's the syntax?
EDIT:
I am using Ruby's DBI library:
dbh.query("SELECT * FROM persons; SELECT * FROM addresses;")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是在谈论 mysql cli 吗?对我来说效果很好:
如果你谈论的是一种特定的语言,那么它取决于你的 mysql 库。例如,PHP mysql 库不支持这一点。但是,如果您使用 multi_query(),mysqli 库就会执行此操作。
are you talking about from the mysql cli? works fine for me:
if you're talking about a specific language, then it depends on your mysql library. for example, the PHP mysql library does not support this. however, the mysqli library does if you use multi_query().
连接人员和地址,您可以得到一个大结果表,假设地址与具有某些标识符的人员相关联。如果这两个查询不相关,为什么要将它们放在一起?
JOIN persons and addresses, and you can get a big result table, assuming addresses correlates to persons with some identifier. If the two queries aren't related, why would you want them together?
如果数据相关,请使用 JOIN 将地址项连接到个人项上。如果您的表都包含相似的列,您可能需要像这样的 UNION SELECT:
SELECT * FROM people
联盟
从地址中选择*;
If the data correlates use a JOIN to join address items onto person items. If your tables both contain similar columns you probably want a UNION SELECT like so:
SELECT * FROM people
UNION
SELECT * FROM addresses;