Forum Moderators: coopster

Message Too Old, No Replies

mysql update

add one row to another

         

Scally_Ally

9:27 am on Jun 14, 2006 (gmt 0)

10+ Year Member



Just a quick one..

Is there a way with SQL and mysql to add two separate columns from the same row together, for example.

"UPDATE MyTable SET column1 = column1 + column2"

I know i can use a script that can open 2 recordsets but was just wondering if it can all be done through sql?

Thanks

eelixduppy

11:07 am on Jun 14, 2006 (gmt 0)



Yes, this should work as you want, however your current query will update all rows in the table. To get around this you should add a WHERE like this:
"UPDATE MyTable SET column1 = (column1 + column2) WHERE column1 = 20"

Good luck ;)

Scally_Ally

11:47 am on Jun 14, 2006 (gmt 0)

10+ Year Member



thanks, i knew there was a simple answer to it