MySQL查询返回语法错误

时间:2014-11-16 15:06:15

标签: mysql select insert

我正在运行这样的查询,但收到错误

insert into oc_product_to_category (product_id, category_id) values (select product_id from oc_product where model='Schar Gluten & Wheat Free Classic White Bread, 14.1 oz (Pack ' and price=36.26 limit 1, select category_id from oc_category_description where name='Bakery & Bread');

我做错了什么?

1 个答案:

答案 0 :(得分:0)

values

您不需要insert . . . select
insert into oc_product_to_category (product_id, category_id)
    select (select product_id
            from oc_product
            where model = 'Schar Gluten & Wheat Free Classic White Bread, 14.1 oz (Pack ' and
                  price = 36.26
            limit 1
           ),
           (select category_id
            from oc_category_description
            where name='Bakery & Bread'
           );

但是,您的问题可能是第二个子查询未被括号括起来。