-2

I have two tables with many to many relation.

table 1:

    Code    |  Product | 
------------+----------+
 00001      | product1 | 
 00002      | product2 | 

table 2:

Tag_id |  name | 
-------+--------
1      | tag1  | 
2      | tag2  | 

associated Table:

Tag_id  | Product_id 
--------+----------+
 1      | product1 | 
 1      | product2 | 
 1      | product3 | 
 2      | product4 |
 3      | product4 | 
 4      | product4 |

Someone please tell me how can i genrate table like display below:

  Code      |  Product | Tags 
------------+----------+---------------
 00001      | product1 | tag1,tag2
 00002      | product2 | tag1,tag3,tag4

Or tags in a multiple columns.

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
M Tahir Noor
  • 423
  • 2
  • 9
  • 29

1 Answers1

0

for mysql
Try this

select Code,Product,Group_concat(name) from table1 
left join associatedTable on table1.product=associatedTable.product_id 
left join table2 on table2.tag_id=associatedTable.tag_id
ashkufaraz
  • 5,064
  • 6
  • 49
  • 79