当前位置:网站首页>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:
边栏推荐
- phpstyle安装管理mysql
- .NET Community Toolkit 8.0.0 版本发布
- 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)
- 【cookie 临时存储数据,WebStorage ,sessionStorage】
- Some optional strategies and usage scenarios for PWA application Service Worker caching
- 8/7 牛客6+div2D+倍增lca
- Redis 定长队列的探索和实践
- vim /etc/profile 写入时 出现 E121:无法打开并写入文件解决方案
- 模式识别 学习笔记:第六章 其他分类方法 (持续更新中。。。)
猜你喜欢
爱可可AI前沿推介(8.8)
Five-faced Alibaba rated P6 after taking the offer: share his interview experience
Alibaba微服务组件Nacos注册中心
鲲鹏开发者创享日2022:鲲鹏全栈创新 与开发者共建数字湖南
微服务负载均衡器Ribbon实战
nvm的使用 nodejs版本管理,解决用户名是汉字的问题
模式识别 学习笔记:第七章 特征选择
安科瑞预付费水电集团物业解决方案-Susie 周
Kunpeng Developer Creation Day 2022: Kunpeng Full-Stack Innovation and Developers Build Digital Hunan
Supervisor 后台进程管理
随机推荐
PM2 入门(二)
PG核心篇--物理存储结构
微服务负载均衡器LoadBalancer实战
宏任务和微任务——三目算符与加号优先级——原生的js如何禁用button——0xff ^ 33 的结果是——in的用法——正则匹配网址
phpstyle安装管理mysql
E121: Unable to open and write file solution when vim /etc/profile is written
一文搞懂│XSS攻击、SQL注入、CSRF攻击、DDOS攻击、DNS劫持
openssl 创建证书
一文读懂配置管理(CM)
leetcode:761. 特殊的二进制序列【递归 + 转换有效括号】
模式识别 学习笔记:第六章 其他分类方法 (持续更新中。。。)
在半小时内从无到有开发并调试一款Chrome扩展(Chrome插件/谷歌浏览器插件)
Pattern Recognition Study Notes: Chapter 6 Other Classification Methods (Continuously updated...)
硬盘数据恢复工具
day01 - Introduction to Web API - Introduction to DOM - Getting Elements - Event Basics - Manipulating Elements - Exclusive Operations - Custom Attribute Operations - Node Operations - Cases: Dynamica
安装MinGW-w64
Yizhou Financial Analysis | Internet-based small loan platform intensively increased capital; comprehensive evaluation index of bank wealth management subsidiaries released in the first half of the ye
写个 shell 玩 数字炸弹
Redis的那些事:一文入门Redis的基础操作
为你的网站加上live2d的动态小挂件,博君一晒