这是我的查询,我得到了这个
#1066 - Not unique table/alias: 'user_rights'
错误。我不认为我有任何多余的逗号或任何东西。什么是真正的错误?我的表名是user_rights,我试图改变它可能是因为它内置功能但它有相同的错误。继承人我的询问
SELECT
tbl_users.ID_NUM,
tbl_users.USERNAME,
user_rights.RIGHTS
FROM tbl_users
INNER JOIN user_group
ON tbl_users.GROUP_ID = user_group.GROUP_ID
INNER JOIN user_rights
ON user_group.GROUP_ID = user_rights.GROUP_ID
INNER JOIN user_rights
ON user_group.GROUP_ID = user_rights.GROUP_ID
INNER JOIN usertypes
ON user_rights.RIGHTS = usertypes.USERCODE
答案 0 :(得分:2)
这是你的问题。
INNER JOIN user_rights
ON user_group.GROUP_ID = user_rights.GROUP_ID
INNER JOIN user_rights
ON user_group.GROUP_ID = user_rights.GROUP_ID
如果你想加入同一个表两次,必须使用表别名,如下所示:
INNER JOIN user_rights ur1
ON user_group.GROUP_ID = ur1.GROUP_ID
INNER JOIN user_rights ur2
ON user_group.GROUP_ID = ur2.GROUP_ID
答案 1 :(得分:0)
你有两次user_rights
表。我认为没有必要。此外,最后JOIN
似乎也没必要。表别名有助于使查询更易于编写和读取。所以,我认为这是你想要的查询:
SELECT u.ID_NUM, u.USERNAME, ur.RIGHTS
FROM tbl_users u INNER JOIN
user_group ug
ON u.GROUP_ID = ug.GROUP_ID INNER JOIN
user_rights ur
ON ug.GROUP_ID = ur.GROUP_ID ;