0

i have little problem with one algo .

first i have two tables there are above one lac records in each table .

 table 1X  structure 
 id      domain
 1      google.com
 2      daniweb.com
 3      yahoo.com

 table 2X  structure 
 id      domain
 1      google.com
 2      facebook.com
 3      youtube.com

now my task is to compare table 2X with Table 1X and compare domains in it
if table 2X domain != table 1X domain then OK insert to Table 1X else ignore and delete Table2x domain becasue its present in table 1X.

am doing php coding for that
last night i write script for that in one way

way1 :: fetch both tables data in assoc array( mysql_fetch_assoc($t1)); and then comapre like
$a=$r1['domain'];
$b=$r2['domain'];
if($a != $b) { //OK else {// not ok}

but this is method is too expensive use too much server ram and cup ..... so not good

so please help me in that task any suitable method that cost me little ram and cpu on server ... thanks

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by smantscheff
0

I assume that id is auto increment.
I am not sure about performance, but this way you can try updting 1x using only 1 query

insert into 1x (id, domain) select id, domain from 2x where domain not in (select domain from 1x);

Now we assume that all rows from 2x is copied to 1x so we can remove all rows from 2x

delete from table2x;

Edited by urtrivedi: -

1

urtrivedi's solution assumes that the (id,domain) tupels are the same in 1X and 2X, i.e. that the IDs for all domains are the same in both tables. Since I do not believe this to be the case and since ID presumably is an auto_increment field, change the above suggestion to:

insert into 1x (domain) select domain from 2x where domain not in (select domain from 1x);
Votes + Comments
thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.