我正在尝试在MYSQL中创建视图,但是在使用Union ALL时,该视图显示在1列下方。当我尝试添加列名时,它只是说列数和结果不匹配
use TestDB;
DROP VIEW if exists auditTableView;
Create view auditTableView
AS
select usernames.username from usernames LEFT JOIN auditTable on usernames.ID = auditTable.userID
Union ALL
select actionDesc.functionName from actionDesc LEFT JOIN auditTable on actionDesc.actionID = auditTable.actionID
Union all
SELECT timestamp from auditTable;
SELECT * FROM auditTableView;
最佳答案
从可以收集的架构中,您似乎想要从auditTable到用户名和actionDesc表进行内部联接,然后从中选择用户名,actionDesc和时间戳值:
use TestDB;
DROP VIEW if exists auditTableView;
Create view auditTableView
AS
select
usernames.username,
actionDesc.functionName,
auditTable.timestamp
from auditTable
inner join usernames
on usernames.ID = auditTable.userID
inner join actionDesc
on actionDesc.actionID = auditTable.actionID;
select * from auditTableView;
关于mysql - 在MySQL中用union创建 View ,但所有记录都显示在1列下,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28286955/