Sql 未知列,但它确实存在?
以下是我的更新查询:Sql 未知列,但它确实存在?,sql,Sql,以下是我的更新查询: UPDATE products SET products_status = 0 WHERE (`products`.`products_id` = `products_to_categories`.`products_id` and `products_to_categories`.`categories_id` = 114) 我得到的错误是: 1054-where子句中的未知列“products\ U to\ U categories.products\
UPDATE products
SET products_status = 0
WHERE (`products`.`products_id` = `products_to_categories`.`products_id`
and `products_to_categories`.`categories_id` = 114)
我得到的错误是:
1054-where子句中的未知列“products\ U to\ U categories.products\ U id”
但当我转到表products\u to\u categories时,有一列products\u id
我做错了什么?明白了:
UPDATE products
SET products_status = 0
WHERE (SELECT products_id FROM products_to_categories
WHERE(
`products`.`products_id` = `products_to_categories`.`products_id` and `products_to_categories`.`categories_id` = 114))
您需要的查询可能是:
UPDATE products
SET products_status = 0
WHERE products_id IN
(SELECT products_id
FROM products_to_categories
WHERE categories_id = 114)
您没有从“产品”到“类别”表中选择任何内容。您需要添加一个子查询来选择要匹配的products\u to\u categories.products\u id。但这不在我的Where子句中吗?您告诉UPDATE语句要做的就是更改products表。products_to_categories表超出了此查询的范围,因此出现错误。因此,我需要在WHERE语句中添加select语句?这仍然不是有效的sql查询语法。看我建议的问题。是的,我能理解为什么你的更漂亮。而且看起来更有用。然而,我的工作无论如何都是有效的。谢谢你的帮助。