选择值时查询失败

时间:2011-02-01 05:10:00

标签: mysql

我将记录从一个表插入到状态为lead的其他表中。现在,两个表中的列数不同,我必须使用字段名称。然而它失败了。不确定原因在哪里

INSERT IGNORE INTO Table1(
         lead_id,
    phone_number,
           title, 
           first_name, 
           middle_initial, 
           last_name, 
           address1, 
           address2, 
           address3, 
           city, 
           state, 
         postal_code, 
         gender, 
         date_of_birth, 
         alt_phone, 
         email,
         comments, 
         question_id, 
         answer_ques,
          situation_id, 
          best_time_contact, 
          specific_datetime, 
          specific_datetime_at, 
          leadcreated_by, 
          leadcreated_by_on,
           leadcreated_by_at, 
          transfer_by, 
          product_id,
      insertDTS    
          )
       SELECT 
        lead_id,
        phone_number,
        title, 
        first_name, 
           middle_initial, 
           last_name, 
           address1, 
           address2, 
           address3, 
           city, 
           state, 
         postal_code, 
         gender, 
         date_of_birth, 
         alt_phone, 
         email,
         comments, 
         question_id, 
         answer_ques,
          situation_id, 
          best_time_contact, 
          specific_datetime, 
          specific_datetime_at, 
          leadcreated_by, 
          leadcreated_by_on,
           leadcreated_by_at, 
          transfer_by, 
          product_id,
      insertDTS    

FROM TABLE2
WHERE TABLE2.status = 'LEAD'

这将有效..不需要价值观 ---感谢

2 个答案:

答案 0 :(得分:5)

根据我对mySql的了解,您不能在同一个insert语句中使用VALUES和SELECT。尝试从声明中删除VALUES MySQL文档显示了insert ... values,insert ... set和insert ... select语句的单独语法。

答案 1 :(得分:2)

     insert into test2(col1, col2) select col1, col2 from test1