2013-03-15 198 views
0

在同一個內部查詢運行多次的情況下,如何定製以下SQL以提高性能?在此先感謝提高性能SQL

DELETE FROM interactionrel 
WHERE (from_interact_id IN(SELECT interaction_id 
          FROM interaction 
          WHERE instance_pk = ?)) 
     OR (to_interact_id IN(SELECT interaction_id 
           FROM interaction 
           WHERE instance_pk = ?)) 
+2

該聲明是無效的語法('這裏(從.. '),並請正確格式化。 – 2013-03-15 11:10:58

+0

它是SQL Server的 – DevelopmentIsMyPassion 2013-03-15 11:11:25

+0

語法是正確的只有我會正確格式化。 DELETE FROM INTERACTIONREL WHERE (FROM_INTERACT_ID IN (SELECT INTERACTION_ID FROM互動的情況INSTANCE_PK =?)) OR (TO_INTERACT_ID IN (SELECT INTERACTION_ID FROM互動的情況INSTANCE_PK =?)) – user1582625 2013-03-15 11:14:15

回答

1
DELETE il 
FROM interactionrel il, 
     interaction 
WHERE (interaction.interaction_id = il.from_interact_id 
      OR interaction.interaction_id = il.to_interact_id) 
     AND interaction.instance_pk = ? 
+0

感謝相同,但它不工作。我正在使用IBM DB2。 SQLCODE = -104,SQLSTATE = 42601,SQLERRMC = JOIN; – user1582625 2013-03-15 11:34:25

2

你可以試試這個 - 雖然你將需要針對優化運行此:

DELETE FROM interactionrel a 
WHERE EXISTS (SELECT * 
       FROM interaction b 
       WHERE b.instance_pl = ? 
        AND (b.interaction_id = a.from_interact_id 
         OR b.interaction_id = a.to_interact_id)) 
+0

它的工作。謝謝.. – user1582625 2013-03-19 10:32:31