#MySQL # Look up data from one table, insert another table

Source: Internet
Author: User
1. If the field of 2 tables is consistent and you want to insert all the data, you can Use this method: INSERT into target table SELECT * from source table; Example: INSERT INTO t_a select * from T_b; 2. If you want to import only the specified fields, you can use this method: INSERT into Target table (field 1, Field 2, ...) SELECT Field 1, Field 2, ... from source table; ( the type of the corresponding field must be consistent ) For example: INSERT into T_a (name, age) Select name, age from T_b where age > 10; 3. If you need to import only records that do not exist in the target table, you can use this method: INSERT into Target (field 1, Field 2 ...). ) SELECT field 1, Field 2 ... From source table where not EXISTS (SELECT * from target table where target table. field = Source table. field); For example: INSERT into T_A (name) select name from T_b where NOT EXISTS (SELECT * from t_a where t_a.name = T_b.name);

#MySQL # Look up data from one table, insert another table

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.