본문 바로가기
Programming/MySQL

[MySQL] 컬럼 & 필드 합치기 concat(), group_concat()

by guru_k 2015. 6. 30.
728x90
반응형

concat()

 

ex ) 

 

concat(columncolumn)

 

item_table​

idx

 category1

category2 

 category3

 5

 1

 2

 3

 

 

select idx, concat(category1, "/", category2, "/", category3) as merge_column 

from item_table 

where idx = 5 

 

 idx

 merge_column

 5

 1/2/3

 

 

 

group_concat()

 

ex)

 

group_concat(field saparator '구분자')

 

item_table

 idx

 category

 5

 1

 5

 2

 5

 3

 

select idx, group_concat(category saparator '/') as group_concat

from item_table

where idx= 5

 

 idx

 group_concat

 5

 1/2/3


728x90
반응형

댓글