This is my two tables:
CREATE TABLE `subject` (
`id` int(11) NOT NULL auto_increment,
`subjectName` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Dumping data for table `subject`
--
INSERT INTO `subject` (`id`, `subjectName`) VALUES
(1, 'Maths'),
(2, 'Science'),
(3, 'English'),
(4, 'Chemistry');
CREATE TABLE `user_subject` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`subject` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Dumping data for table `user_subject`
--
INSERT INTO `user_subject` (`id`, `name`, `subject`) VALUES
(1, 'John', '2,3'),
(2, 'Riya', '1,3,4'),
(3, 'Mack', '1'),
(4, 'Nik', '1,2,3,4');
I want output like:
Name | Subjects
-------------------------------------
John | Science,English
Riya | Maths,English,Chemistry
Mack | Maths
Nick | Maths,Science,English,Chemistry
Please help me to create join for this.
Thanks.