How to separate a string and re build it

D. Aryal

Separating String list and replacing same list with new values in mysql I have following data in my table_1 Table table_1(Currently saved structure)

code        value
12_A        ["A","B","C","D"]  
12_B        ["E","F","G","H"]
12_3        ["I","J","K","L"]

But each code have different values with different description. like::

code    value     description
12_A    A         Apple
12_A    B         Ball
12_A    C         Cat
12_A    D         Dog
12_B    E         Eagle
12_B    F         Flag
.       .         .
.       .         . 
.       .         .

I have to Separate the value list from table_1 and need to save again in same table i.e table_1(in this structure)::

code            value
12_A            ["Apple","Ball","Cat","Dog"]
12_B            ["Eagle","Flag",.......]
12_3            [......................] 
sagi

You can use GROUP_CONCAT() :

UPDATE Table1 s
SET s.value = (SELECT t.code,CONCAT('["',
                           GROUP_CONCAT(t.description ORDER BY t.description SEPARATOR '","'),
                           ']') 
             FROM Table_With_val t
             WHERE t.code = s.code
               AND s.value LIKE CONCAT('%"',t.value,'"%'))

You didn't provide any conclusive information, I assumed the second data sample you provided is an existing table, and table1 is the table you want to update.

NOTE: This is a bad DB structure! it would most defiantly cause problem in the future especially when required to make joins . I strongly advise you to normalize your data and store each description and value in its own record.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to separate a string with a char?

From Dev

How to separate string output?

From Dev

How to separate String

From Dev

How to Separate a string (Arabic string)

From Dev

How to build a string with no repeating character from three (or N) separate list of characters?

From Dev

How separate string, c#

From Dev

How to split string into separate cells

From Dev

How to separate String array data?

From Dev

How to access separate characters in a string?

From Dev

How to separate a string with duplicated characters

From Dev

How to separate special string in android

From Dev

How to separate String array data?

From Dev

How to separate a string of repeating characters?

From Dev

How to change my makefile to build into a separate folder

From Dev

How to build kernel debug info as separate file?

From Dev

how to have a deployed heroku build while maintaining separate development build

From Dev

How to use Parsec to separate a string by a specific string

From Dev

how to separate string by comma and store inside a string

From Dev

How to re-add deleted build settings

From Dev

How to separate the first and last part of a string in a list

From Dev

How to separate a string in commodore 64 basic?

From Dev

how to separate integer numbers from a string?

From Dev

how to separate values in a string index that are char and int

From Dev

How should I separate following three string?

From Dev

How to split a byte string into separate bytes in python

From Dev

How to separate integer value from a string?

From Dev

How do separate a string from a text file

From Dev

SQL: How to separate string values separated by commas?

From Dev

How to match nested strings and not separate string

Related Related

HotTag

Archive