[英]“group” mysql results for better performance of php
I have a table: 我有一张桌子:
ID, TYPE, TITLE
1, book, One
2, music, Tear
3, book, My flow
4, music, Yes
5, flower, Green
SELECT * FROM table WHERE TYPE IN ( book, music );
But now I need somehow to group results and to be able to do this for each TYPE in php - where I say in php echo all "book" TYPEs it should echo "One, My flow". 但是,现在我需要以某种方式对结果进行分组,并能够针对php中的每个TYPE做到这一点-我在php中说,应回显所有“书”类型,它应回显“一个,我的流程”。 The problem is that my table contains 100 000s of lines and result as well.
问题是我的表也包含10万行和结果。 So I need properly "pre-formatted" results for php because it must be fast with many rows.
因此,我需要对php进行适当的“预格式化”结果,因为它必须快速处理许多行。 Any idea please?
有什么想法吗?
尝试这个。
SELECT *, GROUP_CONCAT(TITLE SEPARATOR ', ') as titles FROM table WHERE TYPE IN ( book, music ) group by TYPE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.