Search code examples
mysqlsqlmysql-error-1136

Copying duplicates into new table - Old MySQL version complicates


Due to an older version of MySQL I'm having to use some pretty outdated methods to get things done. At the moment I am trying to copy similar rows to another table based on a few distinct columns. The table holddups will be taking data from assets where the SKU and Description match those of one in holdkey. The command I'm running is:

INSERT INTO holddups
SELECT * 
FROM assets, holdkey
WHERE assets.SKU = holdkey.SKU
AND assets.Description = holdkey.Description

And the error I'm getting is:

#1136 - Column count doesn't match value count at row 1

I hope this is enough to sort this all out, but if not feel free to ask more.


Solution

  • Selecting just * will take all columns from assets and holdkey and try to put it in holdups. But holdups does not have that much columns. Using assets.*will only take all columns of assets and that is what you want, right?

    INSERT INTO holddups
    SELECT assets.* 
    FROM assets, holdkey
    WHERE assets.SKU = holdkey.SKU
    AND assets.Description = holdkey.Description