tags:

views:

19

answers:

1

i have two large tables in a database.

table 1 with 2 fields rank,name

and

table2 with 2 fields rank,name.

both are of 1 million records.

can you write php sql code to fetch those records which exists in table2 but does not exist in table1.

+2  A: 
SELECT *
FROM Table2
WHERE NOT EXISTS (SELECT 1 FROM Table1 WHERE Table1.Rank = Table2.Rank 
AND Table1.Name = Table2.Name)

You didn't state what the key was, or what criteria you wanted, but this should get you going down the right path. This could be slow for large record sets, but again, you didn't say why/what you wanted this for.

Paddy