联合自我与临时表

时间:2014-10-27 17:47:12

标签: mysql union

具有相同临时表的联合不起作用,但如果它是永久表,则同一查询有效。我的完整查询如下。如果t_pair是永久表,它就可以工作。

CREATE TEMPORARY TABLE t_pair AS
select distinct pr_ns_a, pr_ew_a, pr_ns_b, pr_ew_b from t_score;

CREATE TEMPORARY TABLE t_partner AS
select distinct pr_ns_a as partner from t_pair
union
select distinct pr_ew_a as partner from t_pair
union
select distinct pr_ns_b as partner from t_pair
union
select distinct pr_ew_b as partner from t_pair
order by partner;

1 个答案:

答案 0 :(得分:1)

您无法在同一查询中多次引用临时表

http://dev.mysql.com/doc/refman/5.0/en/temporary-table-problems.html