Database merging
Q: My account is the ACC database. The two database tables have the same structure.
For example, the first database has a table house.
ID (automatic number) Name Number Address
1 Zhang Yi 001 District 1
2 Zhang 'er 002 District 1
3 zhangsan 003 Zone 2
The second database also has a table house.
ID (automatic number) Name Number Address
1 zhangsan 003 Zone 2
2, 4, 005, zone 1
3 zhangwu006 Zone 2
Objective: To merge data into a database without duplicate information
After merging, it should be
ID (automatic number) Name Number Address
1 Zhang Yi 001 District 1
2 Zhang 'er 002 District 1
3 zhangsan 003 Zone 2
Four tickets, four 005 zones
5 zhangwu 006 Zone 2
Could you tell me how to write an SQL statement or how to manually use it?
Because the data is large, if the master has the SQL database merging method, you can import the data into SQL and then merge it.
Question added:On the first floor, you canCodeIs it more detailed? I don't know what to do if the two key databases are connected. A: You can directly use left join.
Insert into database 1. DBO. House (name, number, address)
Select a. Name, A. Number, A. Address
From database 2. DBO. House a left join database 1. DBO. House B
On a. Name = B. Name and A. Number = B. Number and A. Address = B. Address
Where B. Name is null
Or
Insert into database 1. DBO. House (name, number, address)
Select a. Name, A. Number, A. Address
From database 2. DBO. House
Where not exists (select * from database 1. DBO. House where name = A. Name and number = A. number and address = A. Address)
The two writing methods are different in efficiency, depending on the data volume in your table.