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