Subject | Re: in clause - using static values vs table values |
---|---|
Author | ian.macintosh |
Post date | 2006-08-11T03:44:08Z |
--- Gary Benade wrote:
Say I have a table TEMP containing the values 1,2,3,4
SELECT * FROM LARGETABLE WHERE MAININDEXVALUE IN (1,2,3,4)
SELECT * FROM LARGETABLE WHERE MAININDEXVALUE IN ( SELECT * FROM TEMP)
Does the second statement get optimised to execute as efficiently as the
first, or is there a performance penalty?
Hi Gary.
Assume Temp containts a field ID, the primary key, then the query would
be best written:
select
L.*
from
LargeTable L
where
L.MainIndexValue = (
select
T.ID
from
Temp T
where
T.ID = L.MainIndexValue
)
That would pan out more efficiently I believe.
Regards,
Ian.
[Non-text portions of this message have been removed]
Say I have a table TEMP containing the values 1,2,3,4
SELECT * FROM LARGETABLE WHERE MAININDEXVALUE IN (1,2,3,4)
SELECT * FROM LARGETABLE WHERE MAININDEXVALUE IN ( SELECT * FROM TEMP)
Does the second statement get optimised to execute as efficiently as the
first, or is there a performance penalty?
Hi Gary.
Assume Temp containts a field ID, the primary key, then the query would
be best written:
select
L.*
from
LargeTable L
where
L.MainIndexValue = (
select
T.ID
from
Temp T
where
T.ID = L.MainIndexValue
)
That would pan out more efficiently I believe.
Regards,
Ian.
[Non-text portions of this message have been removed]