Hello SQL doper experts.
A while ago I created php page for an intranet that used a complex query.
In order to speed up the query I replaced a subquery with a table created using ‘select into’ so that I could then do a ‘select * from’ on that table in the next query. This would speed things up as it would only have to be run once (subqueries seemed to be run for each conditional test thus slowing down the overall query massively)
To simplify I did this…
select somevariable into temptable
from somebigtable where somevariable < somecondition
select somevariable,anothervariable,yetanothervariable
from somebigtable where somevariable not in
(select * from temptable)
This would work fine, and be quick. But it created a potential headache - if more than one person happened to be running this report at the same time there would be an access conflict on ‘temptable’.
I have just googled temporary tables. I was not able to get my answer to this specific question but I did find out how to create a temporary table. So my question is this - will the following query solve the conflict problem…?
select somevariable into **#**temptable
from somebigtable where somevariable < somecondition
select somevariable,anothervariable,yetanothervariable
from somebigtable where somevariable not in
(select * from **#**temptable)
In other words - in this context, does adding the hash cause this table to only ‘exist’ for this scope? and thus avoid conflicts?