{"id":668,"date":"2018-08-29T23:43:52","date_gmt":"2018-08-29T16:43:52","guid":{"rendered":"http:\/\/www.oopsbox.com\/?p=668"},"modified":"2018-08-29T23:51:33","modified_gmt":"2018-08-29T16:51:33","slug":"split-comma-separated-string-to-multiple-rows","status":"publish","type":"post","link":"https:\/\/www.oopsbox.com\/?p=668","title":{"rendered":"Split comma separated string to multiple rows"},"content":{"rendered":"<p>\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e43\u0e04\u0e23\u0e17\u0e35\u0e48\u0e40\u0e04\u0e22\u0e43\u0e0a\u0e49\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19 GROUP_CONCAT() \u0e43\u0e19\u00a0 MySQL \u0e21\u0e32\u0e01\u0e48\u0e2d\u0e19\u0e01\u0e47\u0e1e\u0e2d\u0e08\u0e30\u0e40\u0e14\u0e32\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e08\u0e32\u0e01\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19\u0e19\u0e35\u0e49\u0e44\u0e14\u0e49\u0e27\u0e48\u0e32 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e08\u0e30\u0e40\u0e1b\u0e47\u0e19\u0e04\u0e48\u0e32\u0e15\u0e32\u0e21\u0e04\u0e2d\u0e25\u0e31\u0e21\u0e20\u0e4c\u0e17\u0e35\u0e48\u0e16\u0e39\u0e01\u0e01\u0e23\u0e38\u0e4a\u0e1b (GROUP BY) \u0e41\u0e25\u0e30\u0e19\u0e33\u0e21\u0e32\u0e15\u0e48\u0e2d\u0e01\u0e31\u0e19\u0e14\u0e49\u0e27\u0e22\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22\u0e17\u0e35\u0e48\u0e23\u0e30\u0e1a\u0e38 \u0e1b\u0e01\u0e15\u0e34\u0e04\u0e48\u0e32\u0e14\u0e35\u0e1f\u0e2d\u0e25\u0e15\u0e4c\u0e08\u0e30\u0e40\u0e1b\u0e47\u0e19 comma &#8216;,&#8217; \u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e01\u0e47\u0e08\u0e30\u0e1b\u0e23\u0e30\u0e21\u0e32\u0e13\u0e19\u0e35\u0e49<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">GROUP_CONCAT([DISTINCT] expr [,expr ...]\r\n             [ORDER BY {unsigned_integer | col_name | expr}\r\n                 [ASC | DESC] [,col_name ...]]\r\n             [SEPARATOR str_val])<\/pre>\n<p>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-669\" src=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/MSQL-group_concat.png\" alt=\"\" width=\"629\" height=\"210\" srcset=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/MSQL-group_concat.png 629w, https:\/\/www.oopsbox.com\/wp-content\/uploads\/MSQL-group_concat-300x100.png 300w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><br \/>\n<a href=\"http:\/\/www.mysqltutorial.org\/mysql-group_concat\/\">**\u0e20\u0e32\u0e1e\u0e08\u0e32\u0e01 mysqltutorial<\/a><\/p>\n<p>\u0e02\u0e49\u0e32\u0e07\u0e1a\u0e19\u0e19\u0e35\u0e48\u0e04\u0e37\u0e2d\u0e15\u0e49\u0e19\u0e40\u0e2b\u0e15\u0e38 \u0e21\u0e31\u0e01\u0e08\u0e30\u0e21\u0e35\u0e01\u0e23\u0e13\u0e35\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e44\u0e14\u0e49\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e21\u0e32\u0e41\u0e25\u0e49\u0e27 \u0e19\u0e31\u0e48\u0e19\u0e04\u0e37\u0e2d &#8220;A,B,C&#8221; \u0e41\u0e25\u0e30\u0e40\u0e23\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e41\u0e22\u0e01\u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49\u0e21\u0e32\u0e2d\u0e2d\u0e01\u0e40\u0e1b\u0e47\u0e19\u0e41\u0e15\u0e48\u0e25\u0e30\u0e41\u0e16\u0e27 (\u0e15\u0e32\u0e23\u0e32\u0e07 t \u0e01\u0e48\u0e2d\u0e19\u0e17\u0e35\u0e48\u0e08\u0e30\u0e1c\u0e48\u0e32\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19 GROUP_CONCAT() \u0e19\u0e31\u0e48\u0e19\u0e41\u0e2b\u0e25\u0e48\u0e30) \u0e14\u0e39\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">CREATE TABLE DEMO (\r\n    ID INTEGER PRIMARY KEY AUTO_INCREMENT,\r\n    PID VARCHAR(20) NOT NULL,\r\n    ICD10LIST VARCHAR(255) DEFAULT NULL\r\n);\r\n \r\nINSERT INTO DEMO(ID, PID, ICD10LIST) VALUES(NULL, '101', 'E119,E112,I10'), (NULL, '102', 'E119,E112'), (NULL, '103', 'E119,I10');<\/pre>\n<p>\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e43\u0e19\u0e15\u0e32\u0e23\u0e32\u0e07\u0e40\u0e1b\u0e47\u0e19\u0e41\u0e1a\u0e1a\u0e19\u0e35\u0e49 (\u0e04\u0e38\u0e49\u0e19 \u0e46 \u0e01\u0e31\u0e19\u0e44\u0e2b\u0e21 5555)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-670\" src=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232120-662x336.png\" alt=\"\" width=\"662\" height=\"336\" srcset=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232120-662x336.png 662w, https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232120-662x336-300x152.png 300w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p>**\u0e41\u0e19\u0e27\u0e04\u0e34\u0e14\u0e02\u0e2d\u0e07\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e01\u0e47\u0e04\u0e37\u0e2d\u0e17\u0e33\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e15\u0e32\u0e23\u0e32\u0e07\u0e04\u0e48\u0e32 Index \u0e17\u0e35\u0e48\u0e2d\u0e22\u0e39\u0e48\u0e43\u0e19\u0e0a\u0e38\u0e14\/\u0e40\u0e0b\u0e15\u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e41\u0e22\u0e01\u0e41\u0e15\u0e48\u0e25\u0e30\u0e44\u0e2d\u0e40\u0e17\u0e47\u0e21\u0e2d\u0e2d\u0e01\u0e21\u0e32<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">SELECT\r\n  DEMO.ID,\r\n  DEMO.PID,\r\n  SUBSTRING_INDEX(SUBSTRING_INDEX(DEMO.ICD10LIST, ',', numbers.n), ',', -1) AS ICD10\r\nFROM\r\n  (SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5) numbers INNER JOIN DEMO\r\n  ON CHAR_LENGTH(DEMO.ICD10LIST)-CHAR_LENGTH(REPLACE(DEMO.ICD10LIST, ',', '')) &gt;= numbers.n-1\r\nORDER BY\r\n  PID, n<\/pre>\n<p>\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-671\" src=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232710-662x336.png\" alt=\"\" width=\"662\" height=\"336\" srcset=\"https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232710-662x336.png 662w, https:\/\/www.oopsbox.com\/wp-content\/uploads\/Screenshot-20180829232710-662x336-300x152.png 300w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/p>\n<p>\u0e08\u0e1a\u0e1b\u0e34\u0e4a\u0e07 !!!<\/p>\n<p>\u0e1b.\u0e25.<\/p>\n<ul>\n<li>\u0e15\u0e32\u0e23\u0e32\u0e07 numbers \u0e08\u0e30\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e27\u0e49\u0e01\u0e48\u0e2d\u0e19\u0e01\u0e47\u0e44\u0e14\u0e49 \u0e1b\u0e01\u0e15\u0e34\u0e01\u0e47\u0e43\u0e0a\u0e49\u0e1a\u0e48\u0e2d\u0e22 \u0e46 \u0e19\u0e30\u0e04\u0e23\u0e31\u0e1a\u0e08\u0e30\u0e14\u0e49\u0e27\u0e22 RECURSIVE CTE \u0e01\u0e47\u0e44\u0e14\u0e49\u0e2b\u0e23\u0e37\u0e2d<a href=\"https:\/\/stackoverflow.com\/questions\/14298154\/mysql-sequential-number-table\">\u0e15\u0e31\u0e27\u0e19\u0e35\u0e49<\/a><\/li>\n<li>\u0e15\u0e31\u0e27 Split String \u0e08\u0e30\u0e17\u0e33\u0e40\u0e1b\u0e47\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19\u0e44\u0e27\u0e49\u0e01\u0e47\u0e44\u0e14\u0e49\u0e19\u0e30 ^_^<\/li>\n<li>\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e40\u0e1b\u0e47\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e2a\u0e21\u0e21\u0e38\u0e15\u0e34\u0e08\u0e32\u0e01 Data Exchange \u0e2a\u0e21\u0e21\u0e38\u0e15\u0e34\u0e41\u0e2b\u0e48\u0e07\u0e2b\u0e19\u0e36\u0e48\u0e07<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div id=\"s-share-buttons\" class=\"\"><div class=\"s-single-share\">\n\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"fb-share-button\" data-href=\"https:\/\/www.oopsbox.com\/?p=668\" data-type=\"button_count\"><\/div><\/div><div class=\"s-single-share\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\"><\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t<\/div><div class=\"s-single-share\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"g-plusone\" data-size=\"medium\"><\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div><div class=\"s-single-share\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"\/\/www.pinterest.com\/pin\/create\/button\/\" data-pin-do=\"buttonBookmark\"  data-pin-color=\"red\"><img decoding=\"async\" src=\"\/\/assets.pinterest.com\/images\/pidgets\/pinit_fg_en_rect_red_20.png\" \/><\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<script type=\"text\/javascript\" async defer src=\"\/\/assets.pinterest.com\/js\/pinit.js\"><\/script>\n\t\t\t\t\t\t\t\t\t\t\t\t<\/div><div class=\"s-single-share\">\n\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"mailto:?Subject=Split%20comma%20separated%20string%20to%20multiple%20rows&Body=Here%20is%20the%20link%20to%20the%20article:%20https:\/\/www.oopsbox.com\/?p=668\" title=\"Email\" class=\"s3-email\"><img decoding=\"async\" src=\"https:\/\/www.oopsbox.com\/wp-content\/plugins\/simple-social-share\/includes\/..\/images\/share-email.png\"><\/a>\n\t\t\t\t\t\t\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e43\u0e04\u0e23\u0e17\u0e35\u0e48\u0e40\u0e04\u0e22\u0e43\u0e0a\u0e49\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19 GROUP_CONCAT() \u0e43\u0e19\u00a0 MySQL \u0e21\u0e32\u0e01\u0e48\u0e2d\u0e19\u0e01\u0e47\u0e1e\u0e2d\u0e08\u0e30\u0e40\u0e14\u0e32\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e08\u0e32\u0e01\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19\u0e19\u0e35\u0e49\u0e44\u0e14\u0e49\u0e27\u0e48\u0e32 \u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e08\u0e30\u0e40\u0e1b\u0e47\u0e19\u0e04\u0e48\u0e32\u0e15\u0e32\u0e21\u0e04\u0e2d\u0e25\u0e31\u0e21\u0e20\u0e4c\u0e17\u0e35\u0e48\u0e16\u0e39\u0e01\u0e01\u0e23\u0e38\u0e4a\u0e1b (GROUP BY) \u0e41\u0e25\u0e30\u0e19\u0e33\u0e21\u0e32\u0e15\u0e48\u0e2d\u0e01\u0e31\u0e19\u0e14\u0e49\u0e27\u0e22\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2b\u0e21\u0e32\u0e22\u0e17\u0e35\u0e48\u0e23\u0e30\u0e1a\u0e38 \u0e1b\u0e01\u0e15\u0e34\u0e04\u0e48\u0e32\u0e14\u0e35\u0e1f\u0e2d\u0e25\u0e15\u0e4c\u0e08\u0e30\u0e40\u0e1b\u0e47\u0e19 comma &#8216;,&#8217; \u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e04\u0e33\u0e2a\u0e31\u0e48\u0e07\u0e01\u0e47\u0e08\u0e30\u0e1b\u0e23\u0e30\u0e21\u0e32\u0e13\u0e19\u0e35\u0e49 GROUP_CONCAT([DISTINCT] expr [,expr &#8230;] [ORDER BY {unsigned_integer | col_name | expr} [ASC | DESC] [,col_name &#8230;]] [SEPARATOR str_val]) \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07 **\u0e20\u0e32\u0e1e\u0e08\u0e32\u0e01 mysqltutorial \u0e02\u0e49\u0e32\u0e07\u0e1a\u0e19\u0e19\u0e35\u0e48\u0e04\u0e37\u0e2d\u0e15\u0e49\u0e19\u0e40\u0e2b\u0e15\u0e38 \u0e21\u0e31\u0e01\u0e08\u0e30\u0e21\u0e35\u0e01\u0e23\u0e13\u0e35\u0e17\u0e35\u0e48\u0e40\u0e23\u0e32\u0e44\u0e14\u0e49\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c\u0e21\u0e32\u0e41\u0e25\u0e49\u0e27 \u0e19\u0e31\u0e48\u0e19\u0e04\u0e37\u0e2d &#8220;A,B,C&#8221; \u0e41\u0e25\u0e30\u0e40\u0e23\u0e32\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e41\u0e22\u0e01\u0e02\u0e49\u0e2d\u0e04\u0e27\u0e32\u0e21\u0e17\u0e35\u0e48\u0e44\u0e14\u0e49\u0e21\u0e32\u0e2d\u0e2d\u0e01\u0e40\u0e1b\u0e47\u0e19\u0e41\u0e15\u0e48\u0e25\u0e30\u0e41\u0e16\u0e27 (\u0e15\u0e32\u0e23\u0e32\u0e07 t \u0e01\u0e48\u0e2d\u0e19\u0e17\u0e35\u0e48\u0e08\u0e30\u0e1c\u0e48\u0e32\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e48\u0e19 GROUP_CONCAT() \u0e19\u0e31\u0e48\u0e19\u0e41\u0e2b\u0e25\u0e48\u0e30) \u0e14\u0e39\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e31\u0e19 CREATE TABLE DEMO ( ID INTEGER PRIMARY KEY AUTO_INCREMENT, PID &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.oopsbox.com\/?p=668\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Split comma separated string to multiple rows&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":672,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[78,12],"class_list":["post-668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-note","tag-comma-separated","tag-mysql","entry"],"views":4325,"_links":{"self":[{"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=668"}],"version-history":[{"count":2,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":674,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions\/674"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=\/wp\/v2\/media\/672"}],"wp:attachment":[{"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oopsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}