# Comparing 2 tables & updating records

**URL:** https://forum.kirupa.com/t/comparing-2-tables-updating-records/303356
**Category:** programming
**Created:** [January 19, 2010, 10:10am UTC](https://forum.kirupa.com/t/comparing-2-tables-updating-records/303356 "2010-01-19T10:10:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![prakash\_rc](https://avatars.discourse-cdn.com/v4/letter/p/b77776/32.png) [@prakash\_rc](https://forum.kirupa.com/u/prakash_rc)
#### Post date: [January 19, 2010, 10:10am UTC](https://forum.kirupa.com/t/comparing-2-tables-updating-records/303356/1 "2010-01-19T10:10:40Z")

</div>

Here is what I have

table\_1

id  
new\_id

table\_2

id

what I want to do:

compare table\_1.id with table\_2.id and if they are same replace table\_2.id with table\_1.new\_id

for example

table\_1

1 122  
2 123  
3 124

table\_2

1  
2  
3

after running the script in table\_2 i should get

122  
123  
124

The database is MySQL. Hence even if I get MySQL statement to run directly on database thats fine

Thanks in advance
