开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜