-1

I have a list of beer styles called table: beer_style_list

Where it contains data like this

enter image description here

Now I have sample comma separated values like this

American Lager,American Light Lager,Bock,Bohemian Pilsner,Doppelbock,Märzen,München Helles,Münchner Dunke,Schwarzbier,Vienna Lager

Im trying to get the IDs of each comma separated values from the beer_style_list

output like this

152, 153, 154, 155, 156, 157, 158, 159, 160, 161

with comma separated too.

Pablo
  • 1,357
  • 1
  • 11
  • 40
  • database version? how many entries in your list at most? how big can the ids be? – ysth Sep 15 '20 at 22:00
  • 2
    this is something trivial to do in your client; doing it in sql is possible but is it worth the trouble? – ysth Sep 15 '20 at 22:01
  • 1
    Load it all in, make a look-up table, and use it in your application layer. One query, infinite low-cost look-ups. – tadman Sep 15 '20 at 22:03
  • 1
    [FIND_IN_SET()](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set) might be useful here – WOUNDEDStevenJones Sep 15 '20 at 22:04
  • my question here is, what are you going to do with the integer CSV list? – erik258 Sep 15 '20 at 22:07
  • Im just doing this because I have an excel sheet with multiple records and each one of the rows. has the beer style column that has multiple comma separated values. So I came up with the solution by doing this kind of action. – Pablo Sep 15 '20 at 22:17

1 Answers1

0

GROUP_CONCAT is designed for this.

SELECT GROUP_CONCAT(id) FROM `beer_style_list`
Mech
  • 3,952
  • 2
  • 14
  • 25