Differences and usage of select into from and insert into select

Source: Internet
Author: User

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

Related Article

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.