Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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
Mysql子查询外部在哪里_Mysql_Subquery - Fatal编程技术网

Mysql子查询外部在哪里

Mysql子查询外部在哪里,mysql,subquery,Mysql,Subquery,我试图编写一个mysql查询,通过子查询找到要插入的值,并且只插入到具有指定id的行中。mysql给了我这个错误 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE product_id = '1'' at line 8 但我现在不知道synax应该

我试图编写一个mysql查询,通过子查询找到要插入的值,并且只插入到具有指定id的行中。mysql给了我这个错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE product_id = '1'' at line 8 
但我现在不知道synax应该是什么。我现在的问题是,感谢您的帮助

刘易斯


编辑:我是个白痴,我应该现在就使用UPDATE而不是insert它的fixed。

如果我正确理解了你的问题,我认为你或你想插入一个
产品id=1的新行。

INSERT INTO oc_product (product_id, tax_class_id)
SELECT 1, tax_class_id 
FROM oc_tax_class 
WHERE title = 'Taxable Goods' 

where应用于现有记录,而不是用于创建新记录,我猜您需要在内部选择查询中使用where过滤器,或者您可能需要更新而不是创建新记录insert@MKhalidJunaid你的权利我是一个白痴它的更新和工作感谢:)你可以使用插入有时在这种情况下。您可以使用ON DUPLICATE KEY UPDATE语法。如果你想插入一条不存在的记录,这很有用,但如果它确实存在,就更新它。这是另一种方式,我本想更新,但我很累,谢谢你的输入。
INSERT INTO oc_product (product_id, tax_class_id)
SELECT 1, tax_class_id 
FROM oc_tax_class 
WHERE title = 'Taxable Goods'