合并两个数据库后,我有重复的客户记录,我选择并复制到一个如下所示的表:
ID Address a1 101 Apple Way a2 101 Apple Way b1 102 Banana Place b2 102 Banana Place c1 103 Chocolate River Dr. c2 103 Chocolate River Dr.
我想生成一个如下所示的表:
ID1 ID2 Address a1 a2 101 Apple Way a2 a1 101 Apple Way b1 b2 102 Banana Place b2 b1 102 Banana Place c1 c2 103 Chocolate River Dr. c2 c1 103 Chocolate River Dr.
经过一些操作之后,我会将第二个表格提供给一个程序,该程序将结合两个客户记录并确保更新级联。
我可以使用哪种SQL查询来创建第二个表? 谢谢你看看!
答案 0 :(得分:1)
试试这个......
select t2.id as ID1,t1.ID as ID2,t1.Address from tt t1
inner join tt as t2 on t1.Address=t2.Address and t2.ID<>t1.ID