<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[temporary table - Binary Sludge]]></title><description><![CDATA[dredging the digital quagmire]]></description><link>https://www.binarysludge.com/</link><generator>Ghost 0.11</generator><lastBuildDate>Fri, 01 May 2026 14:55:13 GMT</lastBuildDate><atom:link href="https://www.binarysludge.com/tag/temporary-table/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[MySQL ERROR 1137 (HY000): Can't reopen table: 'tmp_journals']]></title><description><![CDATA[<p>When setting up a query using a temporary lookup table, I got this error:</p>

<pre><code>ERROR 1137 (HY000): Can't reopen table: 'tmp_journals'  
</code></pre>

<p>It transpires that since 4.1 the way MySQL handles temporary tables has changed. This affects joins, unions and subqueries. There is an obvious fix:</p>

<pre><code>mysql&gt; CREATE</code></pre>]]></description><link>https://www.binarysludge.com/2010/03/18/mysql-error-1137-hy000-cant-reopen-table/</link><guid isPermaLink="false">4b1b5222-d865-4542-9fda-e978b7c28df5</guid><category><![CDATA[error]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[temporary table]]></category><dc:creator><![CDATA[Andrew Martin]]></dc:creator><pubDate>Thu, 18 Mar 2010 15:00:49 GMT</pubDate><content:encoded><![CDATA[<p>When setting up a query using a temporary lookup table, I got this error:</p>

<pre><code>ERROR 1137 (HY000): Can't reopen table: 'tmp_journals'  
</code></pre>

<p>It transpires that since 4.1 the way MySQL handles temporary tables has changed. This affects joins, unions and subqueries. There is an obvious fix:</p>

<pre><code>mysql&gt; CREATE TEMPORARY TABLE tmp_journals_2 LIKE tmp_journals;  
Query OK, 0 rows affected (0.00 sec)

mysql&gt; INSERT INTO tmp_journals_2 SELECT * FROM tmp_journals;  
Query OK, 3228659 rows affected (2.01 sec)  
Records: 3228659  Duplicates: 0  Warnings: 0  
</code></pre>

<p>Then the query is easy:</p>

<pre><code>SELECT COUNT(1) cnt, journal_invoice_ref  
FROM tmp_journals  
GROUP BY journal_date  
HAVING cnt &gt; 10000

UNION

SELECT COUNT(1) cnt, journal_invoice_ref  
FROM tmp_journals_2  
GROUP BY journal_invoice_ref  
HAVING cnt &lt; 10  
</code></pre>]]></content:encoded></item></channel></rss>