(这已解决。请参阅下面的答案)
我使用以下查询创建了一个视图:
SELECT TableA.ColA as ColA, User.ID as UserID, User.FirstName, User.LastName, User.Email, TableC.ID as RoleID, TableC.Name as Role FROM Permission
LEFT JOIN TableB ON TableA.ColA = TableB.ID
LEFT JOIN TableD ON TableD.ID = TableB.OrganizationID
LEFT JOIN User ON User.ID = TableA.UserID
LEFT JOIN TableC ON TableC.ID = TableA.RoleID
WHERE User.Active = 1 AND (TableA.ResourceType = 1
OR (TableA.ResourceType = 5 AND TableD.ID = TableB.OrganizationID))
OR User.Active = 1 AND TableC.ID = 1
ORDER BY ColA, UserID ASC
该视图已成功创建并按预期工作。我可以SELECT * ON view_test
毫无问题地对视图进行操作。但是,如果我尝试从视图中选择特定列,例如SELECT ColA FROM view_test
,它会返回以下错误消息:
#1356 - View 'database.view_test' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
我正在运行它的帐户是 root 并且我已经重新授予访问该数据库中所有内容的权限,如果由于某种原因出现了问题。我查看mysql
了数据库部分中的视图,看起来还不错。我可以毫无问题地运行它。我可以做一个SELECT ColA FROM ([view_sql_block_from_above]) as a
,它也可以正常工作。只有在被创建为视图之后,它才会出现这些问题。
任何帮助将不胜感激。
=== 编辑 ===
下面是输出SELECT COLUMNS FROM view_test
show columns from view_test;
+-----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+-------+
| ColA | int(11) | YES | | NULL | |
| ColB | int(10) unsigned | YES | | 0 | |
| ColC | varchar(30) | YES | | NULL | |
| ColD | varchar(30) | YES | | NULL | |
| ColE | varchar(50) | YES | | NULL | |
| ColF | int(10) unsigned | YES | | 0 | |
| ColG | varchar(30) | YES | | NULL | |
+-----------+------------------+------+-----+---------+-------+
7 rows in set (0.00 sec)