【问题标题】:how can i solve following issue: #1241 - Operand should contain 1 column(s) [duplicate]我该如何解决以下问题:#1241 - 操作数应包含 1 列 [重复]
【发布时间】:2020-09-27 16:14:24
【问题描述】:
insert into tbl_cart (ssid,  product_id, product_name, product_price, product_image, quantity) 
values (1234, (select product_id, product_name, product_price, product_image    from tbl_product WHERE product_id=1),1);

【问题讨论】:

    标签: mysql


    【解决方案1】:

    查询:

    select product_id, product_name, product_price, product_image 
    from tbl_product 
    where product_id=1
    

    返回您想要的列,但对于 INSERT ... VALUES,使用返回多于 1 列的查询在语法上是错误的。

    使用INSERT ... SELECT:

    insert into tbl_cart (ssid, product_id,product_name,product_price,product_image,quantity) 
    select 1234, product_id, product_name, product_price, product_image, 1 
    from tbl_product 
    where product_id=1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多