SQL query of multiple values in one cell

后端 未结 2 591
生来不讨喜
生来不讨喜 2020-11-27 23:21

There is a table(Course Interests) which has all the values in one cell. But those values are just ids and I want to join them with another table(Course) so I can know their

2条回答
  •  独厮守ぢ
    2020-11-28 00:27

    Use FIND_IN_SET to search for something in a comma-delimited list.

    SELECT i.MemberID, i.MemberName, GROUP_CONCAT(c.Course) AS CoursesInterested
    FROM CourseInterests AS i
    JOIN Course AS c ON FIND_IN_SET(c.CourseId, i.CoursesInterested)
    

    However, it would be better to create a relation table instead of storing the courses in a single column. This type of join cannot be optimized using an index, so it will be expensive for a large table.

提交回复
热议问题