2011-11-02 109 views
0

当我在MySQL Workbench中运行此语句时,SELECT语句附近出现语法错误。SQL语法错误 - INSERT INTO ... SELECT

INSERT INTO 
    rare_csshop.cscart_product_features_values 
     (feature_id, product_id, value, lang_code) 
VALUES 
    SELECT DISTINCT 
    "10" As Feature, t1.product_id, CONCAT(t2.NHeigth, "\" H x ", t2.NWidth, "\" W x ", t2.NDepth, "\" D") As Dimensions, "EN" As Lang 
FROM 
    rare_csshop.cscart_product_descriptions AS t1, 
    rare_csshop.products AS t2 
WHERE 
    t1.product = t2.NName 

select语句自行运行良好。我错过了什么吗?

回答

3

您需要从查询中删除单词VALUES(您可以插入值或OR SELECT结果)。

2

在选择语句之前取下VALUES。这应该工作。

INSERT INTO 
    rare_csshop.cscart_product_features_values 
     (feature_id, product_id, value, lang_code) 
    SELECT DISTINCT 
    "10" As Feature, t1.product_id, CONCAT(t2.NHeigth, "\" H x ", t2.NWidth, "\" W x ", t2.NDepth, "\" D") As Dimensions, "EN" As Lang 
FROM 
    rare_csshop.cscart_product_descriptions AS t1, 
    rare_csshop.products AS t2 
WHERE 
    t1.product = t2.NName 

我不知道为什么,但我最近才遇到这种情况。可能是当我们指定VALUES时,它只假定值而不是查询结果。

+1

欢迎来到Stackoverflow。只是想让你知道你可以通过选择它并按下Ctrl + K或者{}'按钮来设置你的代码的格式。我已经帮你照顾过了。 –