插入与选择

时间:2012-11-06 15:56:04

标签: php mysql sql

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

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 )

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

3 个答案:

答案 0 :(得分:3)

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

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

阅读INSERT ... SELECT syntax from the manual

答案 1 :(得分:1)

您想使用INSERT INTO otherTable (cols) SELECT <yourColumns> FROM <yourtable>而不是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 

答案 2 :(得分:0)

看起来你有:

  1. 表名
  2. 之前的列表
  3. 要插入的一列,但选择了三列
  4. 此类查询中不需要values个关键字。