(converted actaul data into example data) This is my table-
CREATE TABLE `table1` (
`col1` int(11) NOT NULL AUTO_INCREMENT,
`col2` text,
)
ENGINE=InnoDB AUTO_INCREMENT=1129311 DEFAULT CHARSET=utf8
col1 col2
1 abc,xyx,lmn
Need help in sql query to get output in below format
col1 col2
1 abc
1 xyz
1 lmn
tried below but did not worked
SELECT A.col1,
Split.a.value(',', 'VARCHAR(10)') AS STRING
FROM (SELECT sources, CAST ('<M>' + REPLACE(col2, ',', '</M><M>') + '</M>' AS XML) AS STRING
FROM table1) AS A CROSS APPLY String.nodes ('/M') AS Split(a)
WHERE A.col1=1;