Suppose I've created 2 tables. one is students and another is events. The tables structures and the records are like them. I would like to show the events result in one row separated by commas.
--
-- Table structure for table `events`
--
CREATE TABLE `events` (
`id` int(11) NOT NULL,
`event_name` varchar(100) NOT NULL,
`event_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `events`
--
INSERT INTO `events` (`id`, `event_name`, `event_id`) VALUES
(1, 'dance', 1),
(2, 'sing', 2),
(3, 'acting', 3),
(4, 'debate', 4);
-- --------------------------------------------------------
--
-- Table structure for table `students`
--
CREATE TABLE `students` (
`id` int(100) NOT NULL,
`student_name` text NOT NULL,
`event_id` int(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `students`
--
INSERT INTO `students` (`id`, `student_name`, `event_id`) VALUES
(1, 'student 1', 1),
(2, 'student1', 2),
(3, 'student1', 3),
(4, 'student1', 4),
(5, 'student2', 3);
(6, 'student3', 2);
(7, 'student3', 4);
I want to see the results like this
Students | Events
----------|---------
Student1 | dance, sing, acting, debate
Student2 | acting
Student3 | sing, debate
What would be the SQL query?
Thanks