2013-11-25 16 views
2

我有以下SQL DML更新命令,但語法isn't正確,命令doesn't工作:SQL更新

UPDATE hmsg_vehicle_category 
SET hmsg_vehicle_category.hmsg_id, hmsg_vehicle_category.vehiclecategories_inputname 
SELECT l_p.hmsg_id, tmp_p_vc.inputname 
FROM hmsg_him_product AS l_p INNER JOIN ( SELECT p.id, vc.inputname 
              FROM him_product p INNER JOIN vehicle_category vc 
               ON p.id = vc.product 
              ORDER BY p.id, vc.inputname DESC) AS tmp_p_vc 
    ON l_p.products_id = tmp_p_vc.id 
WHERE l_p.hmsg_id = 171; 

哪有我執行這個SQL命令? snytax中的錯誤在哪裏?

感謝您的幫助!

格爾茨 Marwief

+0

它不清楚你想要更新什麼。你不會告訴它在'hmsg_vehicle_category'中更新哪些行。你在說'UPDATE tableA WHERE tableB.id = 171',這對數據庫來說可能是'UPDATE journey.Distance WHERE desk.Material ='Wood'',你沒有指出任何鏈接2。 – OGHaza

回答

1

喜歡的東西:

update hmsg_vehicle_category set 
    hmsg_id = l_p.hmsg_id, 
    vehiclecategories_inputname = tmp_p_vc.inputname 
from hmsg_him_product as l_p 
    inner join him_product as p on p.id = l_p.products_id 
    inner join vehicle_category as vc on vc.product = p.id 
where l_p.hmsg_id = 171 

被警告,這一次將在hmsg_vehicle_category更新表中的所有記錄。可能要添加到where條款如下:

update hmsg_vehicle_category as hvc set 
    vehiclecategories_inputname = tmp_p_vc.inputname 
from hmsg_him_product as l_p 
    inner join him_product as p on p.id = l_p.products_id 
    inner join vehicle_category as vc on vc.product = p.id 
where 
    l_p.hmsg_id = 171 and hvc.hmsg_id = 171 

但我不能勸告,此刻更具體的東西,因爲它是從你的問題不清楚。