Binary Sludge
MySQL ERROR 1137 (HY000): Can’t reopen table: ‘tmp_journals’
When setting up a query using a temporary lookup table, I got this error:
ERROR 1137 (HY000): Can't reopen table: 'tmp_journals'
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:
mysql> CREATE TEMPORARY TABLE tmp_journals_2 LIKE tmp_journals; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO tmp_journals_2 SELECT * FROM tmp_journals; Query OK, 3228659 rows affected (2.01 sec) Records: 3228659 Duplicates: 0 Warnings: 0
Then the query is easy:
SELECT COUNT(1) cnt, journal_invoice_ref FROM tmp_journals GROUP BY journal_date HAVING cnt > 10000</pre> UNION SELECT COUNT(1) cnt, journal_invoice_ref FROM tmp_journals_2 GROUP BY journal_invoice_ref HAVING cnt < 10
Recent Posts
- Signs that you’re a good programmer
- Signs that you’re a bad programmer
- How to Test Software (or: Teach Yourself to be a QA)
- Know Your Onions (and Antipatterns)
- Clean Code and Clean TDD Cheat Sheets
- The Definitive Guide to Bash Command Line History
- The analogy of print and code reviews
- Recovering from a forced push to a tracked repository
- 10 CoffeeScript One Liners to Impress Your Friends
- UUID API
Archives
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- October 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- October 2010
- April 2010
- March 2010
Pages
Recent Comments





