4

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;")
4

3 回答 3

4

你是从 mysql cli 说的吗?对我来说很好:

mysql> select count(*) from a; select count(*) from a;
+----------+
| count(*) |
+----------+
|     2050 |
+----------+
1 row in set (0.06 sec)

+----------+
| count(*) |
+----------+
|     2050 |
+----------+
1 row in set (0.00 sec)

如果你在谈论一种特定的语言,那么它取决于你的 mysql 库。例如,PHP mysql 库不支持此功能。但是,如果您使用 multi_query(),mysqli 库会执行此操作。

于 2009-10-14T21:04:56.260 回答
2

加入人员和地址,您可以获得一个大结果表,假设地址与具有某些标识符的人员相关。如果这两个查询不相关,为什么要将它们放在一起?

于 2009-10-14T21:03:56.730 回答
-1

如果数据相关,则使用 JOIN 将地址项连接到人员项。如果您的表都包含相似的列,您可能需要这样的 UNION SELECT:

SELECT * FROM people UNION SELECT * FROM 地址;

于 2009-10-15T17:25:42.237 回答