group_concat result not work in IN condition

前端 未结 2 1053
有刺的猬
有刺的猬 2021-01-19 15:14

Is there any possible way to put result of group_concat in IN condition of SQL query.

Here in network master table i have comma separated fields in industryId column

相关标签:
2条回答
  • 2021-01-19 15:26

    I have tried above case but not working on my side. I just edited above answer and removed > 0 then I can see your expected output.

    Can you try below code?

    select * from industry_master where find_in_set(industryId,  (select group_concat(industryId order by cId SEPARATOR ',') 
    from network_master where userId = 123 group by userId)); 
    
    0 讨论(0)
  • 2021-01-19 15:33

    you don't need group_concat and IN clause you can use a join

      select i.* 
      from industry_master i
      INNER JOIN network_master  n on  i.industryId = n.industryId 
      AND n.userId =123
    

    group_concat return a string but you need values so using the string in IN clause don't work correctly.

    or if can work only an a string you could trying using field_in_set > 0

    select * from industry_master 
    where find_in_set(industryId,  select group_concat(industryId order by cId SEPARATOR ',') 
          from network_master where userId =123 group by userId)   ;
    

    or

    0 讨论(0)
提交回复
热议问题