Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 未知列,但它确实存在?_Sql - Fatal编程技术网

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查询语法。看我建议的问题。是的,我能理解为什么你的更漂亮。而且看起来更有用。然而,我的工作无论如何都是有效的。谢谢你的帮助。