I have a table:
CREATE TABLE `Issues` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
I have another table:
CREATE TABLE `Attachments` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`issue_id` int(11) DEFAULT NULL,
`attachment` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
How can I get the data to look like this:
issue_id title attachment1 attachment2 attachment3
--------------------------------------------------------------
1 T1 a1.png a2.png
2 T2
3 T3 b4.gif xyz.doc ttt.file
The problem I can't figure out is how to get the dynamic set of attachments into a dynamic column grouped by issue. I have determined that the maximum amount of attachments for one issue is 12, but the total per ticket can be anywhere from 0-12. I'm stumped...
I've tried this MySQL pivot row into dynamic number of columns, but can't make sense of it in my case because I'm building dynamic columns based on total matches per record...
Any help would be greatly appreciate. Please let me know if this doesn't make sense.
Nino