开发者

MySQL: return single record with 50 IDs, instead of a 50 records with a single ID

开发者 https://www.devze.com 2023-01-28 22:35 出处:网络
I have a table of books. I can select all the books for a certain author: SELECT BookID FROM tblBook WHERE AuthorID=9

I have a table of books.

I can select all the books for a certain author:

SELECT BookID FROM tblBook WHERE AuthorID=9

(returns 4 records):

23
63
85
98

But what if I want to return a single record, with the ID numbers concatenated like this:

23 63 开发者_JAVA技巧85 98

How do I do that?

Using MySQL.


SELECT group_concat(BookID SEPARATOR ' ') FROM tblBook WHERE AuthorID=9 GROUP BY BookID


check out the group_concat function.

0

精彩评论

暂无评论...
验证码 换一张
取 消