我想从用户表中获取电子邮件和密码,其中电子邮件是主键,而我想从用户表中获取余额和AccountID,而帐户ID是外键。并针对该外键我想要来自表帐户的accountNo

SELECT `user`.`email`, `user`.`passwrd`, `useraccounts`.`Balance`, `useraccounts`.`AccountID`, `accounts`.`AccountNo`
FROM `user` , `accounts`
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email`
LEFT JOIN `useraccounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID`

SELECT `user`.`email`, `user`.`passwrd`, `useraccounts`.`Balance`, `useraccounts`.`AccountID`, `accounts`.`AccountNo`
FROM `user` , `accounts`
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email`
LEFT JOIN `useraccounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID`


错误是#1066-非唯一表/别名:useraccounts enter image description here

最佳答案

“您能纠正这个查询吗?”-也许这

SELECT `user`.`email`, `user`.`passwrd`, `useraccounts`.`Balance`, `useraccounts`.`AccountID`, `accounts`.`AccountNo`
FROM `user`
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email`
LEFT JOIN `accounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID`

关于mysql - 查询错误(1066):不是唯一的表/别名:'useraccounts',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58787326/

10-10 23:14