我已經創建了下面的查詢視圖(這已經解決參見下面的答案):
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
沒有問題。
#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,我已經重新授予:但是,如果我嘗試選擇從視圖中的特定列,如SELECT ColA FROM view_test
,它與以下錯誤消息返回訪問此數據庫中的所有內容,如果出於某種原因出現了問題。我查看了數據庫的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)
嘗試SHOW COLUMNS FROM view_test並共享結果。 – JustinDanielson
[如何修復損壞的SQL視圖]的可能的重複(http://stackoverflow.com/questions/8150804/how-to-fix-a-broken-sql-view) –
添加顯示列的輸出到以上問題。 – dustinnewbold