Member Avatar for nova37

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

Recommended Answers

All 2 Replies

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;

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);
commented: thanks +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.