我有从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
从命令行执行此脚本时工作正常,但在Views中,不允许使用临时表。有没有办法在没有它们的情况下做我想要的事情?
答案 0 :(得分: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
答案 1 :(得分:0)
您可以将这些语句合并为一个语句:
SELECT concat('AUTH_', blog.authors.id) as authority FROM db.authors
UNION -- all ?
SELECT authority FROM db.authorities_real`