当前位置:网站首页>SQL INSERT INTO and INSERT INTO the SELECT statement
SQL INSERT INTO and INSERT INTO the SELECT statement
2022-08-08 12:32:00 【night drift ice】
The INSERT INTO statement is used to insert records of information into a table.
Syntax:
The first type, specify the column name and the inserted value
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, valu23, ...);
Second, if all the columns in the table are present, it is not necessary to specify the name of the column in the SQL query.But the order of the values should be the same as the order of the columns in the table.
INSERT INTO table_name
VALUES (value1, value2, value3, ...)
Example:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway')
The INSERT INTO SELECT statement copies data from one table and adds it to another table.
When operating, make sure that the type of the copied data matches the data type of the table to be inserted.
This operation does not affect other data in the destination table.
Syntax:
Copy all data from one table to another.
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
Copy several columns of data from one table to another:
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;
Example:
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;
Insert the result of a Union into a table:
INSERT INTO Team (name, age)
SELECT customer_name AS name, 21 AS age FROM Customers WHERE customer_id IS NOT NULL
UNION
SELECT customer_name, 31 FROM Orders
ORDER BY name;
Get the customer name from the first table, and a fixed number, and the second table, too, and then combine.Then insert into another table.
Reference:
边栏推荐
- GC explanation and tuning of JVM
- 如何在go重打印函数调用者信息Caller
- 论文阅读《Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras》
- phpstyle安装管理mysql
- 鲲鹏开发者创享日2022:鲲鹏全栈创新 与开发者共建数字湖南
- Mysql索引优化实战
- 上周热点回顾(8.1-8.7)
- MeterSphere--开源持续测试平台
- E121: Unable to open and write file solution when vim /etc/profile is written
- Five-faced Alibaba rated P6 after taking the offer: share his interview experience
猜你喜欢
ets declarative ui development, how to get the current system time
研究:有毒的PFAS化学品使全球各地的雨水无法安全饮用
MySQL----索引
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
Combining "xPlus" to discuss the innovation and change of software architecture
#yyds干货盘点#【愚公系列】2022年08月 Go教学课程 005-变量
神经网络分类
Redis的那些事:一文入门Redis的基础操作
报错 | Cannot find module ‘@better-scroll/core/dist/types/BScroll‘
安装MinGW-w64
随机推荐
面试突击72:输入URL之后会执行什么流程?
Redis的那些事:一文入门Redis的基础操作
ets declarative ui development, how to get the current system time
部署spark2.2集群(standalone模式)
5S软件就是将软件应用全维度简单化的软件系统
简短截说阐述redis中事务的使用
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
请问如何实现两个不同环境的MySQL数据库实时同步
LeetCode_1004_最大连续1的个数Ⅲ
ssh 安全 之 密钥登录
shell基础知识合集
nvm的使用 nodejs版本管理,解决用户名是汉字的问题
d切片示例
changes not staged for commit 解决办法
测试开发专栏——序言:总结过去,展望未来
The most complete JVM performance tuning in history: thread + subsystem + class loading + memory allocation + garbage collection
[Horizon Rising Sun X3 Trial Experience] WIFI connection, SSH login, TogetherROS installation (section 2)
深度学习网络结构图绘制工具及方法
LeetCode_487_最大连续1的个数Ⅱ
JPA之使用复合主键