-1

Here is the code that I have tried to make a duplicate of the record with help of id, by keeping the original record with one column value change. I have tried without the id also, as it gets auto increment when inserting, but got errors like You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near.

INSERT INTO 
    `org_emps`
    (
        3,
        `admin_id`, 
        `emp_branch_id`, 
        `emp_name`, 
        'ITSe08A 0002', 
        `emp_designation`, 
        `emp_department`, 
        `emp_father_husband`, 
        `emp_mother`, 
        `emp_wife`, 
        `emp_nominee`, 
        '02-03-2018', 
        `emp_dob`, 
        `emp_gender`, 
        `emp_m_status`, 
        `emp_father_husband_dob`, 
        `emp_mother_dob`, 
        `emp_wife_dob`, 
        `emp_nominee_dob`, 
        `emp_aadhar`, 
        `emp_PAN`, 
        `emp_bank_ac_num`, 
        `emp_bank_ifsc`, 
        `emp_bnk_branch_address`, 
        `emp_pf_status`, 
        `emp_esi_status`, 
        `emp_income_tax`, 
        `emp_tds`, 
        `emp_photo`, 
        `emp_addr1`, 
        `emp_addr2`, 
        `emp_phone`, 
        `emp_email`, 
        `emp_w_off`, 
        `emp_ot_rate`, 
        'March 2, 2018, 8:46 am', 
        1, 
        `emp_key`
    ) 
    SELECT (
        `id`, 
        `admin_id`, 
        `emp_branch_id`, 
        `emp_name`, 
        `emp_org_id`, 
        `emp_designation`, 
        `emp_department`, 
        `emp_father_husband`, 
        `emp_mother`, 
        `emp_wife`, 
        `emp_nominee`, 
        `emp_doj`, 
        `emp_dob`, 
        `emp_gender`, 
        `emp_m_status`, 
        `emp_father_husband_dob`, 
        `emp_mother_dob`, 
        `emp_wife_dob`, 
        `emp_nominee_dob`, 
        `emp_aadhar`, 
        `emp_PAN`, 
        `emp_bank_ac_num`, 
        `emp_bank_ifsc`, 
        `emp_bnk_branch_address`, 
        `emp_pf_status`, 
        `emp_esi_status`, 
        `emp_income_tax`, 
        `emp_tds`, 
        `emp_photo`, 
        `emp_addr1`, 
        `emp_addr2`, 
        `emp_phone`, 
        `emp_email`, 
        `emp_w_off`, 
        `emp_ot_rate`, 
        `emp_created_on`,
        `emp_type`, 
        `emp_key`
    ) 
    FROM 
        `org_emps` 
    WHERE 
        id = 2
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40

2 Answers2

0

Number of insert columns and their values should be same.Your insert statement column and values columns number are not same here.

Ms.KV
  • 214
  • 2
  • 10
0

Constants values must be part of the select part:

INSERT INTO 
    `org_emps`
    (
        `id`,
       `admin_id`, 
       `emp_branch_id`, 
       `emp_name`, 

...   ) 
    SELECT (
        3, 
      `admin_id`, 
      `emp_branch_id`, 
      `emp_name`, 

   ...
    ) 
    FROM 
        `org_emps` 
    WHERE 
        id = 2
Jens
  • 67,715
  • 15
  • 98
  • 113
  • So, What do you say, I did't get. Please help me to fulfill my requirement. – Dara Naveen Kumar Mar 02 '18 at 08:25
  • or else, let me know. How can I duplicate a record in my MySQL db, having id (primary auto increment key of my table) by 1. Keep the original record as it is, with just changing the value of column emp_type. 2. Make a duplicate with auto incremented id, and along with some value changes in couple of columns like emp_doj, emp_type, etc.. – Dara Naveen Kumar Mar 02 '18 at 08:27
  • @DaraNaveenKumar read the code snippet and you should see what i mean. – Jens Mar 02 '18 at 08:32
  • You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '3,`admin_id`, `emp_branch_id`, `emp_name`, 'ITSe08A 0002', `emp_designation`, `e' at line 1 – Dara Naveen Kumar Mar 02 '18 at 08:34
  • Oh!! Okay my dear. Thank you. – Dara Naveen Kumar Mar 02 '18 at 08:34