I have table1 with a field named subjects which is comma delimited with a unique id for each item.
id1's subjects field contains this information: apple, banana, tomato, melon
id2's subjects field contains this information: pineapple,seed,jelly,fish,eel
Some fields contain as little as one subject and some contain as many as 8 subjects, all separated by commas.
I have table2 which contains 8 fields called cat1, cat2, cat3, cat4, cat5, cat6, cat7, cat8.
I am trying to use the below SQL statement to copy subjects field from table1, break it apart by commas and enter it into the 8 possible cat fields in table2 but I keep getting this error message: "A new statement was found, but no delimiter between it and the previous one. (near "SELECT" at position 68)" . Please assist with correcting my code.
UPDATE table2 VALUES (cat1,cat2,cat3,cat4,cat5,cat6,cat7,cat8) SELECT SUBSTRING_INDEX(subjects,',',1) AS cat1, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',2),',',-1) AS cat2, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',3),',',-1) AS cat3, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',4),',',-1) AS cat4, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',5),',',-1) AS cat5, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',6),',',-1) AS cat6, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',7),',',-1) AS cat7, SUBSTRING_INDEX(SUBSTRING_INDEX(subjects,',',8),',',-1) AS cat8 FROM table1 WHERE id=table1.id;
Thanks.
INSERT
part of the query leaving just theSELECT
, what result do you get? – O. Jones