在MySQL中联接同一表的临时表 [英] Join the same table temporary table in MySQL

查看:250
本文介绍了在MySQL中联接同一表的临时表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢在MySQL中加入一个失败的临时表,这个想法很简单:

I like to join a temporary table in MySQL which fails, the idea quite simple:

CREATE TEMPORARY TABLE temp_table LIKE any_other_table; -- srsly it does not matter which table

(
  SELECT p1,p2,p3 FROM temp_table WHERE p4 = 1
) UNION (
  SELECT p1,p2,p3 FROM temp_table WHERE p4 = 2
)

非常感谢您的帮助.

mysql抛出的错误是ERROR 1137 (HY000): Can't reopen table: 'temp_table'

The error thrown by mysql is ERROR 1137 (HY000): Can't reopen table: 'temp_table'

推荐答案

在同一查询中,您不能多次引用TEMPORARY表.

You cannot refer to a TEMPORARY table more than once in the same query.

请阅读以下链接 http://dev.mysql.com/doc/refman /5.5/en/temporary-table-problems.html

这篇关于在MySQL中联接同一表的临时表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆