how to update a specific field(column) of a row by

2019-06-13 20:24发布

问题:

i have below table

  it_id     item_id     item_name   
    1   ite_1            shirt
    2   ite_10           pant
    3   ite_11           socks
    4   ite_12           shoes
    5   ite_13            belt

now i need to change item_id with with ite_(value of it_id of that row)

means if it_id=x then item_id should be ite_x and so on...

what will b sql query for that??

UPDATE ###

if i want to change it_id with a prefix means new it_id=ite_x where x is it's(it_id's) previous value(1,2,3,4,5 etc....) and it_id is not an auto increment field

回答1:

update table_name SET item_id=CONCAT('ite_', id)

SORRY your column id it_id, so it should be (Not Sure Though)

update table_name SET item_id=CONCAT('ite_', it_id)

I think you can do it with follwing steps
1] Change datatype of it_id to VARCHAR
2] your query is

update table_name SET it_id=CONCAT('ite_', it_id)