Insert SQL statements into Table A with four fields: A, B, C, and D. Table B has only three fields: A, B, and C.

Source: Internet
Author: User
If there are two tables (a, B), table A has four fields: A, B, C, and D. Table B only has three fields: A, B, and C, if I want to merge the contents of Table B into Table A, but there is. A = B. in case of a, a is the primary key and repeated values are not allowed. how to do this.
Insert into a select *, null from B where not exists (select 1 from a where a. A = B.),Only 1 is returned, and * can be used, but not exists (select 1 from a where. A = B. a) than exists (select * from a where. A = B. a) higher efficiency.
When the exists keyword introduces a subquery, it is equivalent to a existence test. Simply put, it is equivalent to the WHERE clause of an external query to test whether the row returned by the subquery exists.
Insert into establishes an internal Association.

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.