Skip to main content

Splitting Comma-Separated Values In MySQL

CREATE TABLE numbers (n INT);
 INSERT INTO numbers VALUES
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9),

 

 

https://cdn.sisense.com/wp-content/uploads/image-01-comma-blog.png

select 
  id, 
  substring_index(
    substring_index(email_recipients, ',', n), 
    ',', 
    -1
  ) as email
from dashboards
join numbers
  on char_length(email_recipients) 
    - char_length(replace(email_recipients, ',', '')) 
    >= n - 1
 
https://cdn.sisense.com/wp-content/uploads/image-03-comma-blog.png 


Reference Site : https://www.sisense.com/blog/splitting-comma-separated-values-in-mysql/

Comments

Popular posts from this blog

Advance JS search

 <!DOCTYPE html> <html>     <head>         <title>             Choosen         </title>         <link href="chosen.min.css" rel="stylesheet" type="text/css">              <link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.1/css/font-awesome.min.css" integrity="sha512-TECBPTD5Db97nlsJ/gGBBv9JLXg172YcGtrl/HHM4x9W++PPKEpHs61ogVd4x2omTgST1dIHoy2HeYWZzcZzHw==" referrerpolicy="no-referrer" rel="stylesheet"/>             <style type="text/css">                 .j-filters-level {     min-width: 400px;     border: 1...