开发者

i have two tables in my sql database of 1 million records, is there a way to find out the non matching data

开发者 https://www.devze.com 2022-12-28 23:18 出处:网络
i have two large tables in a database. table 1 with 2 fields rank,name and table2 with 2 fields rank,name.

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 开发者_JS百科exists in table2 but does not exist in table1.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号