Search code examples
mysqlphpmyadmintemporary

MYSQL error on a simple SELECT


Can someone tell my why this code...

DROP TEMPORARY TABLE IF EXISTS parent;
CREATE TEMPORARY TABLE parent (id INT);
INSERT INTO parent VALUES (1);
SELECT * FROM parent;
DROP TEMPORARY TABLE parent;

results in this error (on the SELECT line)...

Table 'sarumcom_cypo.parent' doesn't exist

'sarumcom_cypo' is my database. I have tried variations of this code: with and without the word TEMPORARY, starting with a "USE sarumcom_cypo" line, with a different table name, and with the database name prefixing all references to parent. In all cases I get the error.

If I remove the SELECT, there are no errors. The INSERT reports "# 1 row affected", and the final DROP reports "# MySQL returned an empty result set (i.e. zero rows)".

I am using phpMyAdmin to run this code.


Solution

  • Temporary tables will be deleted when the current client session terminates.