Mysql子查询外在哪里

时间:2014-05-21 15:01:17

标签: mysql subquery

我试图编写一个mysql查询,它将通过子查询找到要插入的值,并且只插入到具有指定id的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应该是什么帮助,我很感激下面是我现在的问题。

路易斯

INSERT INTO oc_product 
        (tax_class_id)
        (
            SELECT tax_class_id 
            FROM oc_tax_class 
            WHERE title = 'Taxable Goods' 
        )
        WHERE product_id = '1'
编辑:我是一个白痴,我本应该使用UPDATE而不是现在插入它的固定。

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,我认为您或希望使用product id = 1插入新行:

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