0

I am working on convert queries from MS SQL Server to MySQL

My SQL Server Query is as per below.

SELECT      userId,IndustriesID,value AS ProvIndusID
FROM        #Talent_list
CROSS APPLY STRING_SPLIT(IndustriesID,',') 

I am stuck here to convert string to row and cross apply.

Need output as per the this picture

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

1 Answers1

0

MySQL doesn't have functions that return tables. You can replace the logic with a recursive CTE:

with recursive cte as (
      select state, cast(null as char(100)) as city, cities, 0 as lev
      from talent_list
      union all
      select state, substring_index(cities, ',', 1),
             substr(cities, length(substring_index(cities, ',', 1)) + 2), lev + 1
      from cte
      where cities <> '' and lev < 5
     )    
select state, city
from cte
where lev > 0;

Here is a db<>fiddle.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786