S.M_Emamian
S.M_Emamian

Reputation: 17383

How to use group by to have parent-child fields

I have a table like this:

title - description
 A          AA
 B          B
 A          AAA
 B          BBBBB

now I would like to have a json like this:

A
  AA
  AAA
B
  B
  BBBB

Is it possible to use one query?

Upvotes: 0

Views: 168

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39497

Based on your sample data, you can use group by with group_concat to get comma separated value for each title:

select title,
    group_concat(description)
from your_table
group by title;

Upvotes: 1

Related Questions