0

In MySQL I've used the function CONCAT_WS to add a value to the textfield.

 UPDATE table SET `textfield`= >>CONCAT_WS('textfield',$randomnumber)<<

Now I've the following entry in the textfield (random numbers), for example:

18, 20, 30, 20, 10

Now I'd like to use a reverse version of the function CONCAT_WS. For example, when I get number 20 (with random PHP-function) I'd like to delete ONLY the last 20 in the row.

18, 20, 30, 20, 10 => 18, 20, 30, 10

When I would have a MySQL-table with a row for each array value instead of a MySQL textfield array, I could do it like this:

DELETE FROM table WHERE `textfield`='20' >>LIMIT 1<<

How can I do the same, but with a mySQL array which I manipulate directly in the database. For example like this:

UPDATE table SET `textfield`= >>DECONCAT_WS('textfield',20)<<

But too bad, this isn't a valid code.

Anyone could help me?

Erwin Augustijn
  • 101
  • 3
  • 10
  • I'm curious why you are de-normalizing your data into a single field like this. Rather than pulling it all into one field, what about a second table with a many to many relationship that achieves the same thing. It will be a heck of a lot easier to manipulate the values you are considering. – Joshua Kaiser Oct 21 '12 at 16:21
  • I believe this is a duplicate of this question: http://stackoverflow.com/questions/5928599/equivalent-of-explode-to-work-with-strings-in-mysql – Joshua Kaiser Oct 21 '12 at 16:23

1 Answers1

0

As i know:

  • There is no such a function in MySQL
  • There is no data-type like array in MySQL
  • There is some set-related string functions, which could help, but these works with only comma as separator, and nothing specifically for this problem.
pozs
  • 34,608
  • 5
  • 57
  • 63