Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare two large tables?

Status
Not open for further replies.

mrbti

Technical User
Feb 28, 2011
5
GB
I have two tables (table1 & table2) that contain fields ID and SITE. Both tables contain one million (1000000) rows each.

I need to compare the SITE field in the tables to find out what data exisits in the second table that does not exist in the first.

I have tried the following but because of such large tables, it seems to limit to 30 results, take forever or just not work at all.

SELECT site FROM `table1`
WHERE `table1`.site
NOT IN (
SELECT site
FROM `table2`
WHERE `table1`.site = `table2`.site
)

I need a way to output the results into a 3rd table. I am using PHP as the base coding language.
 
Code:
CREATE TABLE table3 
SELECT table1.site 
  FROM table1
LEFT OUTER
  JOIN table2
    ON table2.site = table1.site
 WHERE table2.site IS NULL
:)

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top