views:

126

answers:

1

I am using SQL.

Here is an example of my table: (There are actually thousands of rows like these, with varying course numbers.)

Course No | Meeting Day | Course Name | Instructor
123       |      M      |    English  |    Smith
123       |      W      |    English  |    Smith
123       |      F      |    English  |    Smith

I need to concatenate these rows into one like:

123 | MWF | English | Smith

Is this possible? :)

TIA.

+1  A: 

In MySQL, you can use the GROUP_CONCAT function with a GROUP BY:

SELECT
  course_no,
  GROUP_CONCAT(DISTINCT meeting_day SEPARATOR '') days,
  course_name,
  instructor
FROM
  courses
GROUP BY
  course_no, course_name, instructor
Phil Ross
Thank you! But I'm mostly looking to create a new table with this information though, can you help me with this?
You can create a new table from a query in MySQL by running CREATE TABLE name SELECT...
Phil Ross
Thanks very much :)