开发者

return a list from different rows into a single field

开发者 https://www.devze.com 2023-02-19 14:32 出处:网络
I have the following table: animal | name| |----------------| |dog| Fido| |----------------| |dog| Spot| |----------------|

I have the following table:

|animal | name   |
|----------------|
|dog    | Fido   |
|----------------|
|dog    | Spot   |
|----------------|
|dog    | Lassie |
|----------------|
|cat    | Sue    |
|----------------|
|cat    | Ace    |
|----------------|
|cat    | Felix  |
|----------------|
|pig    | Porky  |
|----------------|
|pig    | Arnold |
|----------------开发者_开发问答|

I need an SQL query that will return the following

dog | Fido, Spot, Lassie
cat | Sue, Ace, Felix
pig | Porky, Arnold


select animal, group_concat(name)
from your_table
group by animal
0

精彩评论

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