[英]Comparing two mysql tables and saving differences in third
我正在嘗試比較兩個不同的表,並將不匹配的記錄保存在第三個表中。 假設我們有一個表t1
:
1stID, Title, Forename, Surname, Postcode,
t1field1, t1field2, t1field3 ....
第二表t2
:
2ndID, 2nd_title, 2nd_forename, 2nd_surname,
2nd_postcode, 2nd_field1, 2ndfield2 ...
第三空表t3
具有與表t2
結構。
兩個表中都有成千上萬的記錄和許多其他字段。 ID完全不同。 唯一的方法是在第一個表中不使用空名,姓氏和郵政編碼的情況下進行比較 。 當然結果可能不准確,但是現在對我來說還可以。
什么是比較的最好辦法t1
表t2
使用MySQL的一個表的語句並保存從表不匹配的記錄t2
表t3
?
我可以在PHPMyAdmin或直接在控制台中構造mysql語句。
我已經在網上搜索過,並且有很多方法可以進行選擇,但是沒有答案如何填充第3個表以及如何使用非ID列進行比較。 感謝您的回復。
收集所有not in
table_2中的記錄並插入table_3中
insert into table_3
select * from table_1 where
forename not in (select * from table_2)
or surname not in (select * from table_2)
or postcode not in (select * from table_2)
如果要過濾所有內容,可以將OR
更改為AND
運算符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.