Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Wednesday, September 4, 2013

Concatenate/concat/group_concat two columns/rows with MySQL query

Two/more rows concatenate-
You can use GROUP_CONCAT.
As in:
select person_id, group_concat(hobbies separator ', ')
    from peoples_hobbies group by person_id;
Death: As Dag stated in his comment, there is a 1024 byte limit on result. to solve this run this query before your query:
set group_concat_max_len=2048
Off course, you can change 2048 accourding to your needs.

Two/more columns concatenate-
You can use the CONCAT function like this:
SELECT CONCAT(SUBJECT, ' ', YEAR) FROM table