Mysql message: #1241 - Operand should contain 1 column(s) - Copy data from different tables and databases

Asked

Viewed 157 times

0

I need to copy database A data from table A (14columns) to Database B table A (15columns) I need to check accountid if there is no database B table A must copy the data, if there is no.

I tried the command below deleting the column that has different in both banks and would insert later via Sql, but gave the above error. Anyone can help???

INSERT INTO vtiger_account (accountid, account_no, accountname, parentid, account_type, industry, annualrevenue, rating, ownership, siccode, tickersymbol, phone, otherphone, email1, email2, website, fax, employees, emailoptout, notify_owner, isconvertedfromlead)
SELECT (accountid, account_no, accountname, parentid, account_type, industry, annualrevenue, rating, ownership, siccode, tickersymbol, phone, otherphone, email1, email2, website, fax, employees, emailoptout, notify_owner, isconvertedfromlead) FROM aramat01_vt71.vtiger_account WHERE accountid > 1164
  • Your command does not match the description of what you make of the problem.

  • Hello I understood what you need, but before providing you a possible solution I would like to know the following: The second table has 1 more field, this field is mandatory? after your SELECT there are Parentheses I believe is wrong, try to remove them and run the command again...

2 answers

0

Considering that the extra field in table B, it is not mandatory the code to do what you need will conform below, as you only want to include accountid as long as it does not exist in the table aramat01_vt71.vtiger_account, I used a NOT EXISTS, also removed the parentheses that were among the SELECT.

Another important issue is that in the description of the problem, you say that one table has 14 fields and the other 15, but from what I checked in your query there are 21 fields.

TIP: Before running the script below, just run the/SELECT query, and make sure the data is returning correctly.

INSERT INTO vtiger_account (
accountid, 
account_no, 
accountname, 
parentid, 
account_type, 
industry, 
annualrevenue, 
rating, 
ownership, 
siccode, 
tickersymbol, 
phone, 
otherphone, 
email1, 
email2, 
website, 
fax, 
employees, 
emailoptout, 
notify_owner, 
isconvertedfromlead 
) 
SELECT a.accountid, 
       a.account_no, 
       a.accountname, 
       a.parentid, 
       a.account_type, 
       a.industry, 
       a.annualrevenue, 
       a.rating, 
       a.ownership, 
       a.siccode, 
       a.tickersymbol, 
       a.phone, 
       a.otherphone, 
       a.email1, 
       a.email2, 
       a.website, 
       a.fax, 
       a.employees, 
       a.emailoptout, 
       a.notify_owner, 
       a.isconvertedfromlead
FROM aramat01_vt71.vtiger_account a 
    WHERE NOT EXISTS (
    
        SELECT NULL
          FROM vtiger_account ax
          WHERE a.accountid = ax.accountid
)

-2

Simply remove the parentheses from the SELECT:

INSERT INTO vtiger_account (accountid, account_no, accountname, parentid, account_type, industry, annualrevenue, rating, ownership, siccode, tickersymbol, phone, otherphone, email1, email2, website, fax, employees, emailoptout, notify_owner, isconvertedfromlead)

SELECT accountid, account_no, accountname, parentid, account_type, industry, annualrevenue, rating, ownership, siccode, tickersymbol, phone, otherphone, email1, email2, website, fax, employees, emailoptout, notify_owner, isconvertedfromlead FROM aramat01_vt71.vtiger_account WHERE accountid > 1164

Browser other questions tagged

You are not signed in. Login or sign up in order to post.