Yii Framework Forum: Updating 1 Column In A Table From Another Column In The Same Table? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Updating 1 Column In A Table From Another Column In The Same Table? What is the best method? Rate Topic: -----

#1 User is offline   U4EA 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 04-November 12

Posted 12 January 2013 - 07:05 PM

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

#2 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 131
  • Joined: 23-January 12
  • Location:Paris - France

Posted 14 January 2013 - 03:41 AM

Hi,
you can use query builder to execute a SQL command (called from a controller action).
See
http://www.yiiframew...uilding-queries
0

#3 User is offline   U4EA 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 04-November 12

Posted 14 January 2013 - 04:14 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users