RE: [Q] Another SQL question???
Posted in 1995
Saqib,
What is the goal of this select? Offhand, I'd say that it doesn't
sound like you really need the temp table. Perhaps, this would
work:
SELECT t1.col1, t1.col2, t1.col3, t3,col1
FROM table1 t1, table3 t3
WHERE t1.col1 = "xyz"
AND t1.col3 = t3.col1
UNION
SELECT t2.col1, t2.col2, t2.col3, t3,col1
FROM table2 t2, table3 t3
WHERE t2.col1 = "xyz"
AND t1.col3 = t3.col1
If this won't work for you, then sure, keep using the temp table.
But, you will need to drop the table between iterations. This is MUCH
faster than deleting each row one-by-one.
Sorry, no clues on your need for a stored procedure. I don't
understand enough of whay you're doing. But, I don't ~think~ you
need a stored proc.
--Craig (craig@chemistry.utah.edu)
>
> I have constructed the following query with the help of Net God(esses).
>
> select col1, col2, col3 from table1 where col1="xyz"
> union
> select col1, col2, col3 from table2 where col1="xyz"
> into temp temp_table;>
> select temp_table.col1, temp_table.col2, temp_table.col3, table3.col1
> from temp_table, table3
> where temp_table.col3=table3.col1>
> This works fine, except the data in table3 is being continuosly updated
> so I need to run this query repeatedly. That is not a problem EXCEPT,
> once a TEMP table temp_table has been created, Informix gives an error
> saying that the table still exists. ANY way around that????
>
> Secondly, I can INSERT the UNION result INTO a real table and just keep
> updating to it, EXCEPT all the new info will be APPENDED to temp_table,
> which will make the second part of the query slow down. I can always
> DELETE * from temp_table at the start, however for that I will require a
> stored procedure.
>
> If I am going to be writing a stored procedure, would this be a good way
> of handling this particular query?
>