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 [email protected];[email protected] 1
5271 [email protected] 0
834 [email protected];[email protected]; [email protected] 1
27 [email protected] 1
1977 (null) 0
224 1
88 [email protected] 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 [email protected]
123 [email protected]
5271 [email protected]
834 [email protected]
834 [email protected]
834 [email protected]
27 [email protected]
88 [email protected]
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.