I'm working on a rather simple homework assignment where I have to retrieve some data that complies with some criteria and then run another query on the data that was selected in the previous query.
I create a temporary table and populate it with the results of the first query and then run a second query on the table. Then I drop the table.
Here's the problem: If I drop the table, the second query is empty as result is discarded. I don't understand this. I don't use temporary table for select, only for data validation. And yet if the table is dropped at the end of the query, the query returns empty. If I don't drop the table it works fine. But if I run the query again it says table exists. What am I doing wrong here. Here's the code:
SELECT DISTINCT gno
INTO TEMPORARY TABLE TMP
FROM edge
WHERE weight>100;
SELECT gname, gsum(graph.gno)
FROM TMP, graph
WHERE graph.gno = TMP.gno AND gsum(graph.gno)>=ALL
(SELECT gsum(graph.gno)
FROM graph);