MySQL Arrays: Can this be done?

别来无恙 提交于 2019-12-11 07:45:11

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9024248/mysql-arrays-can-this-be-done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!