简体   繁体   English

错误 #1242 子查询返回多于 1 行

[英]Error #1242 Subquery returns more than 1 row

UPDATE tbl_products
SET Stocks = (Select Stocks 
              WHERE Product_ID IN (3,4,6)) - (SELECT Quantity 
                                              FROM tbl_transactions 
                                              WHERE Product_ID IN (3,4,6) 
                                                AND Date_Time BETWEEN '2020-09-20' AND '2020-09-22');

#1242 - Subquery returns more than 1 row #1242 - 子查询返回超过 1 行

My problem is, how can I make the "Stocks" accept multiple rows or is it even possible?我的问题是,我怎样才能让“股票”接受多行,或者甚至可能吗? Is there other solutions besides this?除了这个还有其他解决办法吗? I already run the subquery and it returned 3 rows and I need that 3 rows to be accepted by "Stocks" so it will subtract the values from my first table.我已经运行了子查询,它返回了 3 行,我需要“Stocks”接受这 3 行,这样它就会从我的第一个表中减去这些值。

SET stocks can only take one value. SET 股票只能取一个值。 Your subquery is returning more than one.您的子查询返回不止一个。 Make sure it can only return one value.确保它只能返回一个值。 Run the subquery by itself to confirm.单独运行子查询以确认。

You should only be assing a single value to a SET of columns.你应该只assing一个值的SET列。 eg例如

SET a = 'test', b = 'something'

However, if you would like to update multiple rows, you would need INSERT IGNORE or to update all the table rows with a specific value then you would just need to write a proper WHERE condition.但是,如果您想更新多行,则需要INSERT IGNORE或使用特定值更新所有表行,然后您只需要编写适当的WHERE条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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