0

我有从 MySQL 数据库获取权限的身份验证系统。

CREATE TEMPORARY TABLE db.temp (authority VARCHAR(100));
INSERT INTO db.temp (authority) SELECT blog.authors.id FROM db.authors;
UPDATE db.temp SET authority=CONCAT("AUTH_",authority);

SELECT authority FROM db.temp
UNION
SELECT authority FROM db.authorities_real

从命令行执行时,此脚本工作正常,但在视图中,不允许使用临时表。没有他们有什么办法可以做我想做的事吗?

4

2 回答 2

2

为什么不只UNION使用authors表格:

SELECT CONCAT('AUTH_',blog.authors.id)
FROM db.authors
UNION 
SELECT authority 
FROM db.authorities_real

您无需创建临时表,只需db.authors使用UNION. 这样做你不必使用临时表。

UNION将从查询中删除所有重复项。如果您不介意重复或不期望任何重复,那么我会使用UNION ALL

于 2013-01-10T14:51:26.210 回答
0

您可以将这些语句组合成一个:

SELECT concat('AUTH_', blog.authors.id) as authority FROM db.authors
UNION -- all ?
SELECT authority FROM db.authorities_real`
于 2013-01-10T14:51:20.433 回答