1

For example, if I have a table structure like this:

Table 1
    ID Name Value

    001 Rajesh 90,100,210,400
    002 Suresh 100,400,300,66
    003 Mahesh 200,500
    004 Virat 400,578,57

How can I delete 400 from Suresh?

DELETE Value ="400" FROM table1
WHERE Name = 'Suresh'

This doesn't work.

1
  • Possible duplicate of: stackoverflow.com/questions/14642658/… Also see Docs: ftp.nchu.edu.tw/MySQL/tech-resources/articles/… To remove set elements from an existing set, we use the REPLACE function to remove the element. If using decimal values, we use a combination of the bitwise AND operator & with the bitwise NOT operator ~. UPDATE set_test SET myset = REPLACE(myset,'Dancing','') WHERE rowid = 6; UPDATE set_test SET myset = myset & ~2 WHERE rowid = 6; Commented Jul 13, 2015 at 17:03

1 Answer 1

1

I would recommend splitting the values into a second table which is related via the person's ID. However, you can use the following query for your current situation:

UPDATE table1
SET Value = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', Value, ','), ',400,', ','))
WHERE Name = 'Suresh'

Here's a SQL Fiddle. For reference, see MySQL's string functions

Sign up to request clarification or add additional context in comments.

1 Comment

is there any way we can change this in hql ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.