SQL statement for help, do not know how to write.
I now have two tables A and B table A table has a field is Zhanghao,mobile, b table has zhanghao,username,address, now there are a total of 15 data, B table has 20 data, I want to table A and B table the same field values are inserted into the third list, The extra five data is also inserted into the third table, that is, equal to insert into a piece of data, not equal to reinsert into a piece of data, how to do? Thank you.
------Solution--------------------
Insert the C table with an equal number of a and B linked accounts inserted in table D
SQL Code
INSERT into C (Field 1, Field 2, Field 3) field 1, Field 2, Field 3 from A, B where A.zhanghao = B.zhanghao; INSERT into D (Field 1, Field 2, Field 3) field 1, Field 2, Field 3 from A, B where a.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 A);
------Solution--------------------
I mean if the values of the same field in table A and B are inserted into the third table with equal value, if not equal, only the a table data is inserted into the third list.
You're asking me to feel awkward.
A
1 mobile1
2 Mobile2
3 Mobile3
B
1 Zhang BJ
2 Li Shang
4 Wang Ji
is not zhanghao the same, the A+B data into C, and a in the presence of B does not exist only to insert a C???
------Solution--------------------
And a, B, no?
INSERT INTO C
SELECT * from A, B where A.zhanghao=b.zhanghao
Union
SELECT * FROM A
Union
SELECT * FROM B
------Solution--------------------
So the person who asks the question does not describe the problem clearly and wants us to answer the person to get him out.
Hey ~~~~~
------Solution--------------------
discuss
And a, B, no?
INSERT INTO C
SELECT * from A, B where A.zhanghao=b.zhanghao
Union
SELECT * FROM A
Union
SELECT * FROM B