0

I have 2 tables

Table A

+-------------------------+
| A_id     unique_id      |
+-------------------------+
| 1         1             |
| 2         1             |
| 3         1             |
| 4         2             |
| 5         2             |
+-------------------------+

Table B

+------------------------+
| A_id  unique_id   tags |
+------------------------+
| 1         1         A  |
| 2         1         B  |
| 3         1         c  |
| 4         2         D  |
| 5         2         E  |
+------------------------+   

I want to join these table and get all the tags for each unique_id and i need these concatenated tags for each a_id.How can this be achieved by a single query with a join and group by and group_concat?any other approach will also be helpful

o/p

+-----------------+
|  A_id     tags  |
+-----------------+
| 1         A,B,C |
| 2         A,B,C |
| 3         A,B,C |
| 4         D,E   |
| 5         D,E   |
+-----------------+
John Woo
  • 258,903
  • 69
  • 498
  • 492
pranali
  • 21
  • 1

1 Answers1

0

use Group_concat or group by

select  A_id,
(select Group_concat(tags) From table T1 
where  T1.unique_id= T2.unique_id group by unique_id) tags
From table T2
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20