ChrVik ChrVik - 1 year ago 66
MySQL Question

Move MySql data from two columns into one

I'm trying to move data (update) from two columns into one. Want to slim down my database and get rid of unnecessary columns.

So far I have tried this

UPDATE db SET firm = firm_stone AND firm_concrete


UPDATE db SET firm = firm_stone, firm_concrete


UPDATE db SET `firm` = `firm_stone`, `firm_concrete`

I get the #1064 - You have an error in your SQL syntax

All the columns are present in the db. Not an expert, so hopefully someone spots the error

Answer Source

You have to concatenate these 2 column's value to a single string to keep that in a same column.

UPDATE db.tablename SET firm = concat_ws(' ',firm_stone, firm_concrete); 

here ' ' a blank space will be placed with the 2 strings. You can use your own.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download