2011-02-01 2 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' 

이것은 MYSQL의 내 지식에 따라, 당신이 값을 사용할 수 없습니다와 같은 삽입 문에서 값을 선택 --- 감사

+0

우수. 나는 같은 대답에 늦었다;) – Naved

답변

5

에 대한 필요성을 work..no 것입니다 . 명령문에서 VALUES를 제거하십시오.
MySQL 문서에서는 insert ... values, insert ... set 및 insert ... select 문에 대한 별도 구문을 보여줍니다.

2
 insert into test2(col1, col2) select col1, col2 from test1 
관련 문제