2011-11-02 87 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或者{}'按鈕來設置你的代碼的格式。我已經幫你照顧過了。 –