Search code examples
mysqljoingroup-concat

mysql inner join group_concat mysql


TABLE 1 : 
ID         CODE 
1,2,3,4,5  abc
2,3,4,5    xyz 

TABLE 2 :
ID   NAME
1    NM1
2    NM2
3    NM3
4    NM4
5    NM5

join is on ID . I need to fetch NAME using join where CODE = 'abc'

Any help appreciated


Solution

  • Try function find_in_set:

    select tbl2.name
    from tbl1
    join tbl2 on find_in_set(tbl2.id, tbl1.id) > 0
    where tbl1.code = 'abc'
    

    demo here.