Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to copy&modify data from one field to another? 1

Status
Not open for further replies.

gdbsti

Technical User
Jul 15, 2003
29
0
0
US
Greetings all. I'm not sure if this belongs here or in php forum but...

I have a MySQL database accessed via PHP. I've written query_update_1 (below) to modify "column_2" to '9' when column_1 is between a specified range.

Current
|column_1| column_2| column_3|
____________________________
| 5000 | 7 | Null |
| 5001 | 7 | Null |
| 5002 | Null | Null |
| 5003 | Null | Null |


<code>
$query_update_1 = "update Table set column_2 = '9' where column_1 between '5002' and '5003'";

$result_update_1 = mysql_query($query_update_1);

if(!$result_update_1){
$error_message = "Number insert failed. Sorry";
require("error_page_2.php");
exit;
}
</code>


Query Update_1 Result

| column_1 | column_2| column_3|
_____________________________
| 5000 | 7 | Null |
| 5001 | 7 | Null |
| 5002 | 9 | Null |
| 5003 | 9 | Null |


Now, what I want to do is run another query (or one at the same time) to modify and carry the data in column_1 field to the column_3 field with a text mod, ie:


Desired Update_2 Result.

| column_1 | column_2 | column_3|
_____________________________
| 5000 | 7 | Null |
| 5001 | 7 | Null |
| 5002 | 9 | Stat 5002 |
| 5003 | 9 | Stat 5003 |

Can this be achieved within the same query, or do I need to set up a loop or..??
Any and all input much appreciated.

TIA
Bruce
 
How about something like:
[tt]
UPDATE tbl
SET column_2=9,column_3=CONCAT('Stat ',column_1)
WHERE column_1 BETWEEN 5002 AND 5003
[/tt]


-----
ALTER world DROP injustice, ADD peace;
 
Thanks Tony,

Works perfectly..

Much appreciated, have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top