During development and testing, applications often encounter situations where table replication is required, for example, copying some or all of the fields of Table 1 data to table 2, this is the time when select into or insert into select plays an infinite role. As for the differences and usage of the two methods, please take a look at them!
(1) insert into select statement
Statement format: Insert into Table2 (field1, field2, field3,...) select value1, value2, value3,... from Table1
This usage requires that the inserted Table Table2 must exist. Because the inserted Table Table2 already exists, in addition to inserting the field of the source table Table1, we can also insert custom constants.
(2) select into from statement
Statement format: SELECT vale1, value2, value3 into Table2 from Table1
This method requires that the table 2 to be inserted does not exist because table 2 is automatically created during insertion and the specified field data in table 1 is copied to table 2.
Note: MySQL does not support the select into from statement, but it can replace other SQL statements. For details, refer to this article here:
Alternative solution for MySQL select into from statement
Articles you may be interested in
- Select into from prompt Undeclared variable... solution to the error
- Differences between window. navigate and window. location. href
- Differences between echo, print, print_r, var_export, and var_dump in php
- Differences in the usage of tinyint, smallint, int, and bigint types in mysql
- Detailed explanation of the difference between display: inline; and float: left;
- Use break, continue, goto, return, and exit in multiple loops in PHP
- Php prompts Call to undefined function curl_init () Error Solution
- SMTP Error cocould not connect to SMTP host. send fail