简体   繁体   中英

“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". The problem is that my table contains 100 000s of lines and result as well. So I need properly "pre-formatted" results for php because it must be fast with many rows. Any idea please?

尝试这个。

SELECT *, GROUP_CONCAT(TITLE SEPARATOR ', ') as titles FROM table WHERE TYPE IN ( book, music ) group by TYPE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM