I know there is plenty on here about duplicate rows and columns, but I have a single cell (intersection of row and column) that has multiple values that are comma delimited.
This would be somewhat trivial in some scripting language, but I want to keep in MySQL.
I have table checks and the last columns with there are two val1
values and only one should be returned.
+--------+----------+-------------+----------+----------------------------+
| id | date | doc | amount | column_with_multiple_vals |
+--------+----------+-------------+----------+----------------------------+
| 346862 | 3/7/2017 | WIRE 111111 | 24651.33 | val1, val2, val3, val1 |
+--------+----------+-------------+----------+----------------------------+
Looking around I think this is how it might happen.
Load Data Local Infile
SET @myArrayOfValues = column_with_multiple_vals
- I am a little uncertain of how to go about deduplicating the values in this simulated MySQL array.
I found this ariticle and seemed like it was on the right track of how of what I am looking for.
How can I simulate an array variable in MySQL?
SET @myArrayOfValue = '2,5,2,23,6,';
WHILE (LOCATE(',', @myArrayOfValue) > 0)
DO
SET @value = ELT(1, @myArrayOfValue);
SET @myArrayOfValue= SUBSTRING(@myArrayOfValue, LOCATE(',',@myArrayOfValue) + 1);
INSERT INTO `EXEMPLE` VALUES(@value, 'hello');
END WHILE;