Q:

MySQL separate data to two new columns

One column contains a comma between data and I want to show these different data in two new columns to my question. Examples of data, column CarAndYear: [Volvo, 1995]
I want the 'Volvo' to be displayed in the column Cars and the year '1995 'in the column Year. I would be very grateful for help with this MySQL issue.

A:

Assuming that you always have leading and trailing brackets:
SELECT TRIM(SUBSTR(CarAndYear, 2, INSTR(CarAndYear, ',') - 2)) Cars, 
       TRIM(SUBSTR(CarAndYear, INSTR(CarAndYear, ',') + 1, LENGTH(CarAndYear) - INSTR(CarAndYear, ',') -1)) `Year`
FROM (SELECT '[Volvo, 1995]' CarAndYear) n

Output
+-------+-------+
| Cars  | Year  |
+-------+-------+
| Volvo |  1995 |
+-------+-------+

