-1

I am facing an issue with a mysql query. I need to copy data from one table to another table. The query I am using is:

mysql> insert into voucher (code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at) select (code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at) from voucher_log ;

But, I am getting the below error on executing this:

ERROR 1241 (21000): Operand should contain 1 column(s)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Agniswar Bakshi
  • 328
  • 5
  • 21
  • Please format your code as code & quotes as quotes. Please google your error message without specific names. What happens when you simplify your query until there is no error then add stuff back? Please read & act on [mcve]. – philipxy Dec 15 '17 at 06:03

1 Answers1

5
insert into voucher 
    (code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at) 
select 
    (code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at) 
from voucher_log ;

your query should be

insert into 
    voucher (code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at) 
select 
    code, amount, expire_at, state, driver_id, asset_account_id, created_at, updated_at, creator_id, agent, voucher_batch_id, image, city_id, country_id, serial_number, updater_id, redeemed_at 
from voucher_log ;

you are putting () in the select query. that part is wrong.

Abhijit Kumbhar
  • 923
  • 3
  • 23
  • 49
smn_onrocks
  • 1,282
  • 1
  • 18
  • 33