I do not know how to write SQL statements for help. I have two tables, table A and Table B, with the following fields: zhanghao, mobile, and Table B: zhanghao, username, and address. Currently, table A has 15 data records in total, table B has 20 data records. I want to insert the same field values of Table A and Table B to the third table, insert the excess five pieces of data into the third table for help.
I have two tables, table A and Table B, with the following fields: zhanghao, mobile, and Table B: zhanghao, username, and address. Currently, table A has 15 data records in total, table B has 20 pieces of data. I want to insert the same field values of Table A and Table B into the third table, and insert the excess five pieces of data into the third table, that is, insert data to a data record equally, and insert data to a data record unevenly. how can this problem be solved? Thank you.
------ Solution --------------------
Use tables A and B to join tables with the same account. insert tables C with different inserted tables D.
SQL code
Insert into c (Field 1, field 2, Field 3) field 1, field 2, Field 3 from a, B where. zhanghao = B. zhanghao; insert into d (Field 1, field 2, Field 3) field 1, field 2, Field 3 from a, B where. zhanghao! = B. zhanghao;
------ Solution --------------------
Insert into C select * from A, B where A. zhanghao = B. zhanghao;
Insert into C select * from B where zhanghao not in (select zhanghao from );
------ Solution --------------------
I mean if the values of the same fields in Table A and Table B are the same, insert A piece of data to the third table. if the values are not the same, insert the data in table A to the third table.
I think it's awkward for you.
A
1 mobile1
2 mobile2
3 mobile3
B
1 zhang bj
2 li shang
4 wang ji
Is it true that, like zhanghao, A + B data is inserted into C, while B does not exist in A only inserts A into C ???
------ Solution --------------------
What if A and B do not?
Insert into C
Select * from A, B where A. zhanghao = B. zhanghao
Union
Select * from
Union
Select * from B
------ Solution --------------------
Therefore, the person who asks the question does not describe the question clearly and asks us to answer the question.
Ah ~~~~~
------ Solution --------------------
Discussion
What if A and B do not?
Insert into C
Select * from A, B where A. zhanghao = B. zhanghao
Union
Select * from
Union
Select * from B