2011-02-01 81 views
2

我將一個表中的記錄插入狀態爲主導的其他記錄。現在有兩個表中的列數是不同的,我必須使用字段名稱。然而它的失敗。不知道在哪裏的原因是在選擇值時查詢失敗

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' 

這將work..no需要值 ---感謝

+0

太好了。我被延遲迴答同樣的問題;) – Naved 2011-02-01 05:19:42

回答

5

按我的MySQL的知識,就不能使用值,並在相同的插入語句select 。嘗試從聲明中刪除VALUES。
MySQL文檔顯示insert ... values,insert ... set和insert ... select語句的單獨語法。

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