SQL statements, do not know how to write

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.