用 SELECT 插入
本教程将介绍用 SELECT 插入的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。
问题描述
I have a query that inserts using a SELECT
statement:
INSERT INTO courses (name, location, gid)
SELECT name, location, gid
FROM courses
WHERE cid = $cid
Is it possible to only select "name, location" for the insert, and set gid
to something else in the query?
解决方案
Yes, absolutely, but check your syntax.
INSERT INTO courses (name, location, gid)
SELECT name, location, 1
FROMcourses
WHERE cid = 2
You can put a constant of the same type as gid
in its place, not just 1, of course. And, I just made up the cid
value.
好了关于用 SELECT 插入的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。