Home > Archive > PHP SQL > June 2006 > comparing two mysql tables
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
comparing two mysql tables
|
|
|
| Hy
Plz help me.
I have two identical mysql tables. I nead to compare it and update the
diferences.
table1
id name surname zauzetost
--------------------------
1 John Doe 0
2 Jane Doe 1
3 Mike Dean 0
table2
id name surname zauzetost
--------------------------
1 John Doe 0
2 Jane Doe 0
Ok, in table 1 i have 'zauzetost' with it's values, now script neads to
compare its values and if found diference update table2 with table1 values.
In this case: Jane Doe from table1 'zauzetost' value is 1, in table2 is 0.
Its diferent so script neads to update table2 'zauzetost' value for Jane Doe
into 1.
Not very complicated, buth i dont know how to make it.
Tnx in advance for your brain cells.
Dejan
| |
| ZeldorBlat 2006-06-24, 8:06 am |
|
Dejan wrote:
> Hy
>
> Plz help me.
> I have two identical mysql tables. I nead to compare it and update the
> diferences.
>
> table1
> id name surname zauzetost
> --------------------------
> 1 John Doe 0
> 2 Jane Doe 1
> 3 Mike Dean 0
>
>
> table2
> id name surname zauzetost
> --------------------------
> 1 John Doe 0
> 2 Jane Doe 0
>
>
> Ok, in table 1 i have 'zauzetost' with it's values, now script neads to
> compare its values and if found diference update table2 with table1 values.
>
> In this case: Jane Doe from table1 'zauzetost' value is 1, in table2 is 0.
> Its diferent so script neads to update table2 'zauzetost' value for Jane Doe
> into 1.
>
> Not very complicated, buth i dont know how to make it.
> Tnx in advance for your brain cells.
> Dejan
Assuming that the id column is the same in both tables:
update table2
set zauzetost = t1.zauzetost
from table2 t2, table1 t1
where t2.id = t1.id
| |
|
| tnx very very much.
this solved my problem.
ZeldorBlat <zeldorblat@gmail.com> wrote in message
news:1150981336.894298.254440@u72g2000cwu.googlegroups.com...
>
> Dejan wrote:
values.[color=darkred]
is 0.[color=darkred]
Doe[color=darkred]
>
> Assuming that the id column is the same in both tables:
>
> update table2
> set zauzetost = t1.zauzetost
> from table2 t2, table1 t1
> where t2.id = t1.id
>
|
|
|
|
|