简体   繁体   中英

Error on Insert - error code 1241. operand should contain 1 column(s)

I receive this error :

Error code 1241. operand should contain 1 column(s)

INSERT INTO 66_stock (
    product_stock_id,
    stock_product, 
    stock_product_categories, 
    stock_product_region, 
    stock_product_type, 
    stock_product_ranked, 
    stock_product_status
    )
VALUES (
    66, 
    'testaarea',
    (
        SELECT 
            product_categories, 
            product_region, 
            product_type, 
            product_ranked, 
            product_status 
        FROM website_products 
        WHERE product_id = 66
    )
);

can you help me ?

MySQL expects the subquery to return a single column - which it doesn't.

You can rewrite this as an INSERT ... SELECT statement, as follows:

INSERT INTO 66_stock (
    product_stock_id,
    stock_product, 
    stock_product_categories, 
    stock_product_region, 
    stock_product_type, 
    stock_product_ranked, 
    stock_product_status
)
SELECT 
    product_id, 
    'testaarea', 
    product_categories, 
    product_region, 
    product_type, 
    product_ranked, 
    product_status 
FROM website_products 
WHERE product_id = 66;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM