0

I have a table (img1) in mysql, and want to show the data at a php page which Col2 data will be combined if Col1 is same value (like the format of img2).
Question:
To handle the combining process, do it in sql query or in php is better? And how can I do so? Thank you.
img1
img2

0

2 Answers 2

1

Something like that:

SELECT COl1, GROUP_CONCAT(COL2, SEPARATOR ' ') as COL2 FROM Table GROUP BY COl1
Sign up to request clarification or add additional context in comments.

Comments

0
select id, group_concat(`Col1` separator ',') as `ColumnName`
from
(
  select id, concat(`Col1`, ':',
  group_concat(`Col2` separator ',')) as `Col1`
  from mytbl
  group by id, `Col1`
) tbl
group by id;

You can see it implemented here : Sql Fiddle Demo. Exactly what you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.