2014-01-22 52 views
0

我如何轉換以下查詢加入如何轉換查詢加盟

UPDATE name_master 
SET 
    is_available = 'n', 
    session_id = '18f05294fab50f30c13eea6304722376' 
WHERE 
    name_id IN (SELECT 
      * 
     FROM 
      (SELECT 
       nm.name_id 
      FROM 
       name_master AS nm 
      JOIN product_master AS pm ON nm.name_id = pm.product_code 
      WHERE 
       nm.is_available = 'y' 
        AND nm.is_approval_needed = 'n' 
        AND nm.STATUS = 'active' 
      LIMIT 1) AS t) 
+0

我們可以重新開始嗎? – Strawberry

+0

這是什麼意思? –

回答

1
UPDATE name_master AS nm 
    JOIN product_master AS pm ON nm.name_id = pm.product_code 
SET 
    nm.is_available = 'n', 
    nm.session_id = '18f05294fab50f30c13eea6304722376' 
WHERE 
    nm.is_available = 'y' 
    AND nm.is_approval_needed = 'n' 
    AND nm.STATUS = 'active' 

我看不出有任何的列從條件product_master。這裏加入了足夠的標準嗎?

+0

product_master僅用於JOIN,不需要其他過濾器。 –

+0

查詢產生的錯誤爲:錯誤1221(HY000):UPDATE和LIMIT的用法不正確 –

+0

對不起,我忘記禁止使用涉及多個表的'LIMIT'條件。 –

0
UPDATE nm 
SET 
    is_available = 'n', 
    session_id = '18f05294fab50f30c13eea6304722376' 
FROM name_master nm 
INNER JOIN 
product_master pm 
ON nm.name_id = pm.product_code 
WHERE 
    nm.is_available = 'y' 
    AND nm.is_approval_needed = 'n' 
    AND nm.STATUS = 'active' 
+0

這是MSSQL的語法。 –