我有以下 3 个表:
users:
id, username
folders:
id,fkuser(connects to user.id)
folder_comments:
id,fkuser(connects to user.id), fkfolder(connects to folder.id)
我想获取评论者用户名(folder_comments.fkuser->user.id<->user.username
)和文件夹所有者的用户名(folder_comments.fkfolder->folder.id<->folder.fkuser->user.id<->user.username
);
我想到的查询是部分的:
SELECT `folder_comments`.*, `folder`.`fkuser` as folderuserid, `user`.`firstname` as username
FROM `folder_comments`
left join `folder` on `folder_comments`.`fkfolder` = `folder`.`id`
left join `user` on `folder_comments`.`userid` = `user`.`id`
如何获取文件夹的所有者用户名?
编辑 :
我试过了:
SELECT `folder_comments`.*, `folder`.`fkuser` as folderuserid, `user`.`firstname` as username, , `user`.`firstname` as folderowner
FROM `folder_comments`
left join `folder` on `folder_comments`.`fkfolder` = `folder`.`id`
left join `user` on `folder_comments`.`userid` = `user`.`id`
left join `user` on `folder`.`fkuser` = `user`.`id`
但我得到一个错误Not unique table/alias: 'user'