MySQL: Convert number to string

To copy value from a column in table a to a column in table b, the syntax is straight forward:

insert into new_table (new_column)
select old_column from old_table

But when new_column is varchar and old_column is integer, you will get an error.

You need to use cast function. Update the above query as follows:

insert into new_table (new_column)
select cast(old_column as char) from old_table

Leave a Reply

Your email address will not be published. Required fields are marked *