Home > Database > Mysql Tutorial > How to insert values ​​into a table with the help of MySQL self-calculated output?

How to insert values ​​into a table with the help of MySQL self-calculated output?

王林
Release: 2023-09-06 09:09:09
forward
729 people have browsed it

如何借助 MySQL 自计算输出将值插入表中?

We can insert values ​​into the table through the self-calculated output returned by MySQL. In this case we don't need to use a virtual "dual" table. The syntax can look like this:

INSERT INTO table_name(column1,column2,column3,…) Select value1,value2,value3,…;
Copy after login

Example

In the example below, we use the output of MySQL self-calculation to insert values ​​into the 'testing' table.

mysql> Create table testing(id int, item_name varchar(10));
Query OK, 0 rows affected (0.15 sec)

mysql> Insert into testing (id,item_name)Select 1,'Book';
Query OK, 1 row affected (0.11 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> Insert into testing (id,item_name)Select 2,'Pen';
Query OK, 1 row affected (0.11 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> select * from testing;

+------+-----------+
| id   | item_name |
+------+-----------+
| 1    | Book      |
| 2    | Pen       |
+------+-----------+

2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to insert values ​​into a table with the help of MySQL self-calculated output?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template