MySQL插入选择的结果 [英] MySql insert the results of a select
本文介绍了MySQL插入选择的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我是否可以运行这样的请求:
I would like to know if I can run a request like that:
INSERT INTO t2 (a, b)
VALUES (
SELECT a, b
FROM `t1` AS o
WHERE o.id NOT
IN (
SELECT a
FROM t2
)
)
这个想法是用t1的一些数据填充t2,但是我在语法上一定是错误的.
The idea is to fill the t2 with some data from the t1, but I must be wrong on the syntax.
感谢您的帮助
推荐答案
从SELECT
语句插入时,请勿使用VALUES
关键字.
You don't use the VALUES
keyword when inserting from a SELECT
statement.
INSERT INTO t2 (a, b)
SELECT a, b
FROM `t1` AS o
WHERE o.id NOT
IN (
SELECT a
FROM t2
)
这篇关于MySQL插入选择的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文