在MySQL中加入同一个表临时表

Rob*_*Rob 4 mysql sql join temp-tables

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

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
)
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏.

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

vcs*_*vcs 6

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

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