0
我無法在mysql中運行查詢。特意我不想做select id from roles
...mysql查詢錯誤1054 - 未知列
查詢
select rtu.role_id
from roles r
where id =(select role_id
from roles_to_user rtu
where user_id=1)
錯誤
ERROR 1054 (42S22): Unknown column 'rtu.role_id' in 'field list'
遞減roles_to_user:
+---------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| user_id | int(11) | NO | PRI | NULL | |
| role_id | int(11) | NO | PRI | NULL | |
+---------+---------+------+-----+---------+-------+
遞減角色:
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(80) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
旁邊的語法,兩者之間有區別嗎? – Nir
是的。第一個查詢對於用戶的多個角色失敗。第二個返回每一行的記錄。對於許多記錄可能會有性能差異,但可以使用'explain select ...'來檢查 –