插入到.....选择 [英] INSERT INTO.....SELECT FROM
本文介绍了插入到.....选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将卡路里
作为 fruits
的第一个值,我做不到,任何人都可以帮忙吗?
i want to put calory
as the first value of fruits
, i couldn't do it, can anyone help?
$sql = 'INSERT INTO fruits VALUES('', ?, ?, ?)'
SELECT calory
FROM diet
WHERE fruit = ?
';
$this->db->query($sql, array($a, $b, $c, $d));
推荐答案
正确的语法是:
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
在您的情况下,应为:
INSERT INTO fruits (calory)
SELECT calory
FROM diet
WHERE fruit = ?
(如果卡路里"是表水果"中列的名称)
(if "calory" is the name of the column in the table "fruits")
这篇关于插入到.....选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文