SQL语法错误 - INSERT INTO ... SELECT

时间:2011-11-02 21:52:26

标签: sql

当我在MySQL Workbench中运行此语句时,我在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语句可以自行运行。我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

在select语句之前取消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时,它只假设值不是查询结果。