The schema for the table is :
CREATE TABLE `authors` (
`authorid` int(10) NOT NULL AUTO_INCREMENT,
`emailaddress` varchar(255) DEFAULT NULL,
'send' int(1) DEFAULT '0',
`status` int(1) DEFAULT '0',
PRIMARY KEY (`authorid`),
UNIQUE KEY `authorid` (`authorid`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=latin1;
Sample data :
123 john@smith.com;sue@test.org 1
5271 sally@john.doe 0
834 jacob@tom.smith;foo@bar.net; big@data.cow 1
27 tuesday@rubys.eat 1
1977 (null) 0
224 1
88 miles@per.hour 1
Note : (null)
above is not the text null, but an actual null value
What I would like, is a query that can get the data from the second column and return a result set as follows :
id email
------------------------
123 john@smith.com
123 sue@test.org
5271 sally@john.doe
834 jacob@tom.smith
834 foo@bar.net
834 big@data.cow
27 ruby@tuesdays.eat
88 miles@per.hour
I am looking for something more generic like this example for SQL Server
SELECT A.[State],
Split.a.value('.', 'VARCHAR(100)') AS String
FROM (SELECT [State],
CAST ('<M>' + REPLACE([City], ',', '</M><M>') + '</M>' AS XML) AS String
FROM TableA) AS A CROSS APPLY String.nodes ('/M') AS Split(a);
Which does exactly what I want to do, but I want to do it in MySQL (as you can see from the picture a demonstration of what the above SQL Server query does)
I firmly believe that when provided with a way to do something in a language, it stands to reason there must be a way to UNDO that very same thing. In MySQL, you can pivot data one way with GROUP_CONCAT
, so there must be some what to ungroup data.