There are two tables, each of which contains about data table fields: idpidname .... table 2 field: idpidage .... now we want to merge the table data with idpidnameage... how can we achieve better results? There are two tables, each of which has approximately data records?
Table field:
Id pid name ....
Table 2 fields:
Id pid age ....
Now we want to merge the table data.
Id pid name age...
Better implementation
Reply content:
There are two tables with about data per table
Table field:
Id pid name ....
Table 2 fields:
Id pid age ....
Now we want to merge the table data.
Id pid name age...
Better implementation
Assume that the pid of the table "age" is as follows:
1 2 3 4 5 6 7 ...
Then the pid of the name table is as follows:
1 3 5 6 ...
That isname.pid (foreign key references on age.pid)
We can try the following SQL statement:
SELECT * FROM name RIGHT OUTER JOIN age ON name.pid = age.pid ;
Just write SQL merge. I don't know if the IDs and PIDs of the two tables are the same.
Is the merge online? Or offline? Must the database provide external services?
If only one id is retained, table t1 is retained as an example.
Insert into t3 (id, pid, name, age) select t1.id, t1.pid, t1.name, t2.age from t1, t2 where t1.pid = t2.pid;
If both IDs must be retained
Insert into t3 (id1, id2, pid, name, age) select t1.id, t2.id, t1.pid, t1.name, t2.age from t1, t2 where t1.pid = t2.pid;
insert into t3(pid,name,age) select t1.pid,t1.name,t2.age from t1 left join t2 on t1.pid = t2.pid