2

In my database I have a few records like these with 2 columns:

 Id, Name,

11,  Meal 997,
12,  Meal 998,
13,  Meal 999,
14,  Meam 000,
15,  Meam 001,
16,  Meam 002,

But this was an issue in the application with the wrong data due to a logical error. How can we change the records containing Meam to Meal and also continue incrementing?

The above records should be like these:

11,  Meal 997,
12,  Meal 998,
13,  Meal 999,
14,  Meal 1000,
15,  Meal 1001,
16,  Meal 1002,

How can we change the database?

"Meam 001" will be in one columm

What would the query be?

3 Answers 3

4
update tablename
set name=replace(name,'Meam','Meal 1')
where name like "Meam%"

you can test it with:

select name, replace(name,'Meam','Meal 1')
from tablename

;)

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

3 Comments

seems this was tricky, now it shows as "Meal 1 001", "Meal 1 002". How can we concate as "Meal 1001". thanks for your answer :)
Just change >>replace(name,'Meam','Meal 1')<< with >>replace(name,'Meam ','Meal 1')<< NOTE THE space after Meam !
thanks a lot , now i need to focus on Mysql functions seriously :)
1

Would not a simple SQL UPDATE query be enough?

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

or have I totally misunderstood the question, apologies if I have...

Comments

1
update tablename
set name='Meal' , intvalue=concat('1',intvalue)
where name='Meam'

in the table: name is the columname of the column containing Meal or Meam. intvalue is the columname of the column containing the integer number.

I hope it helps.

1 Comment

Hi Dynodix, both will be in one column name ie. column Name contains "Meam 001", "Meam 002". thanks in advance

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.