mySql - creating a join using a list of comma separated values

前端 未结 2 972
[愿得一人]
[愿得一人] 2021-01-05 14:32

I\'ve got a table with a field for Merchant\'s name and field with the Services they provide. The Services field is a comma separated list of integers that relate to another

2条回答
  •  再見小時候
    2021-01-05 15:15

    The short term solution to your issue is to use the FIND_IN_SET function to join the MERCHANT and SERVICES tables:

    SELECT *
      FROM MERCHANT m
      JOIN SERVICES s ON FIND_IN_SET(s.service_id, m.services) > 0
    

    The long term solution is to correct your tables - never allow columns to contain comma separated lists of referential ID/etc values.

提交回复
热议问题