mysql - 查询在选择值时失败

标签 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'

这会起作用..不需要值 ---谢谢

最佳答案

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

关于mysql - 查询在选择值时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4859142/

相关文章:

计数不同时的 MySQL 案例

php - 根据小于当前日期的列和空列选择数据

mysql - 使用MySQL转储每个数据库的一些数据库表

php - 自定义表单,计算答案然后更新 mysql DB

mysql - 按 sql 查询中的 c_criticality 字段对表进行排序

mysql - order by 的 SQL 规范中的区分大小写 - oracle 与 mysql

java - Hibernate:hbm2ddl 属性值,创建删除总是删除架构,即使没有显式 SessionFactory 关闭?

php - 学说 2 : Getting records based on at least one record with a specific attribute?

mysql - 警告 : Using unique option prefix pass instead of password is deprecated and will be removed in a future release. 请使用全名代替

mysql - 兼容 mysql 插入的 Perl 格式数组元素