Updating 1 Column In A Table From Another Column In The Same Table?

Hi folks,

I have a table and I want to run a SQL update statement that will update one column/field from another in the same DB. So, for examples, I was to update tablename.column2 to the value of tablename.column1. What is the best way to do this? It should be noted that there there is no condition required i.e. no WHERE statement needed - all the rows should be affected.

BTW the table is already modeled.

Hi,

you can use query builder to execute a SQL command (called from a controller action).

See

http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder#alternative-syntax-for-building-queries

Hi mate,

Thanks for the help. I managed to work it out myself in the end - I tried a direct SQL query, which didn’t seem to be working. It turns out it was the table schema that was causing an issue where it wouldn’t update.

Thanks though.