开发者

Replace in MySQL

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?

开发者_JAVA百科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?


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

;)


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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜