1

你好我想从选择查询的列中插入值

insert into (cmts) stat_alert 
values(SELECT stat_alert.cell,stat_alert.cmts,cell_cmt.cmts FROM stat_alert`LEFT OUTER JOIN cell_cmt ON cell_cmt.`cell`=stat_alert.cell WHERE stat_alert.`cell`=cell_cmt.cell )

我有语法错误谁能帮助我??

4

3 回答 3

3

您不需要VALUES关键字和圆括号:

INSERT INTO <table name> (<comma separated column list>)
SELECT <comma separated column list> FROM <table name>

阅读INSERT ... SELECT手册中的语法

于 2012-11-06T15:57:41.667 回答
1

你想使用INSERT INTO otherTable (cols) SELECT <yourColumns> FROM <yourtable>not INSERT INTO ... VALUES()

insert into stat_alert (cmts)  -- list your columns here to insert into
SELECT cell_cmt.cmts  -- your values to be inserted are here
FROM stat_alert
LEFT OUTER JOIN cell_cmt 
    ON cell_cmt.`cell`=stat_alert.cell 
WHERE stat_alert.`cell`=cell_cmt.cell 
于 2012-11-06T15:58:39.747 回答
0

看起来你有:

  1. 表名前的列列表
  2. 要插入一列,但选择了三列
  3. values此类查询中不需要关键字时的关键字。
于 2012-11-06T15:58:58.517 回答