2011-02-01 9 views
2

ステータスがリードであるレコードに、あるテーブルから別のテーブルにレコードを挿入しています。今、私はフィールド名を使用する必要があります両方のテーブルで列の数が異なるsincce。しかし、その失敗。わからない原因は値の選択時にクエリが失敗する

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' 

これは、MySQLの私の知識を1として、あなたはVALUESを使用することはできませんし、同じINSERT文でSELECT値 ---おかげ

+0

グレート。私は同じ答えに遅れていた;) – Naved

答えて

5

の必要性をwork..noますです。ステートメントからVALUESを削除してみてください。
MySQLのドキュメントでは、insert ... values、insert ... setおよびinsert ... select文の構文が異なります。

2
 insert into test2(col1, col2) select col1, col2 from test1 
関連する問題