MySQL Arrays: Can this be done?

2019-08-01 06:03发布

Is it possible to select the concatenation of all the results returned by a subquery?

So if the subquery returns more than one row, I can somehow get all the results contained in a single string?

2条回答
Evening l夕情丶
2楼-- · 2019-08-01 06:22

Sort of. What you can get is the concatenated result of all the rows that were grouped together using GROUP_CONCAT. You could use that to employ GROUP BY by a column that you know would group the result set correctly and then using the function to return the concated groups. The manual page should provide some examples.

查看更多
贪生不怕死
3楼-- · 2019-08-01 06:48

Some MySQL clients, such as the MySQL Command-Line tool, can export the result set in various formats, such as XML.

If you're using a programming language that implements the MySQL client/server protocol through some type of API, it seems like building the array would be trivial in code. PHP's MySQL API returns results in an array.

If you're talking about grouping multiple rows in a result set into a single row, then take a look at GROUP_CONCAT.

查看更多
登录 后发表回答