Reputation: 325
here is my query and i got this
#1066 - Not unique table/alias: 'user_rights'
error. i dont event think i have any excess commas or anything. what is the real error? my table name is user_rights, and i have tried to changed it maybe because its a built in funtion but it have the same error. heres my query
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
Upvotes: 0
Views: 113
Reputation: 1269693
You have the user_rights
table twice. I don't think that is necessary. Also, the last JOIN
also seems unnecessary. Table aliases help make the query easier to write and to read. So, I think this is the query you want:
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 ;
Upvotes: 0
Reputation: 5246
Here's your problem.
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
If you want to join the same table twice you have to use a table alias, like so:
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
Upvotes: 2