Subject | Re: [ib-support] Selects and Updates based on sub-queries |
---|---|
Author | Svein Erling Tysvær |
Post date | 2002-05-08T08:05:08Z |
Hmm, sorry if this is being sent twice - I got some error trying to send it
making me uncertain whether it actually reached its destination.
---
Congratulations Sean, you managed to confuse Helen to give you the wrong
answer (that happens very rarely with simple questions)!
The correct SQL to execute this query lightening fast (unless there is no
index for Temp_Table.RecNo or I am confused too) is:
UPDATE Table1
SET Flag = -1
WHERE EXISTS(SELECT 1 FROM Temp_Table WHERE Temp_Table.RecNo =
Table1.RecNumber)
The problem with the original query is that the subselect is executed once
for each record. Using EXISTS is generally much better (if you care about
speed or CPU usage) than using IN <subselect>.
The bad news is that using temporary tables is not generally recommended
with Interbase. Normal tables holding values temporarily is OK though.
Set
making me uncertain whether it actually reached its destination.
---
Congratulations Sean, you managed to confuse Helen to give you the wrong
answer (that happens very rarely with simple questions)!
The correct SQL to execute this query lightening fast (unless there is no
index for Temp_Table.RecNo or I am confused too) is:
UPDATE Table1
SET Flag = -1
WHERE EXISTS(SELECT 1 FROM Temp_Table WHERE Temp_Table.RecNo =
Table1.RecNumber)
The problem with the original query is that the subselect is executed once
for each record. Using EXISTS is generally much better (if you care about
speed or CPU usage) than using IN <subselect>.
The bad news is that using temporary tables is not generally recommended
with Interbase. Normal tables holding values temporarily is OK though.
Set