所以我试图获得只有作为管理员角色的名字的值 当我在FROM命令之后立即放置WHERE命令时,我得到一个错误
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN `users` AS `u` ON u.uid = ur.uid INNER JOIN `role` AS `r` ON r.rid = ' at line 9
但是,当我把它放在整个事情的最后,它在下面我没有得到任何错误,但我得不到任何结果!
SELECT f.field_first_name_value,
l.field_last_name_value,
r.name,
u.name,
u.mail,
u.created
FROM `users_roles` AS `ur`
INNER JOIN `users` AS `u` ON u.uid = ur.uid
INNER JOIN `role` AS `r` ON r.rid = ur.rid
INNER JOIN `field_data_field_first_name` AS `f` ON f.entity_id = ur.uid
INNER JOIN `field_data_field_last_name` AS `l` ON l.entity_id = ur.uid
WHERE 'role.name' = 'admin'
我能做些什么才能得到我想要的东西。
答案 0 :(得分:3)
将其更改为:
WHERE r.name = 'admin'
您编写它的方式是,您要比较两个文字字符串,而不是将列与字符串进行比较。
此外,您必须使用r.name
而不是role.name
- 一旦为表分配了别名,就无法引用原始表名。