查询错误(1066):不是唯一的表/别名:'useraccounts'

时间:2019-11-10 09:32:10

标签: mysql qsqlquery

我想从用户表中获取电子邮件和密码,其中电子邮件是主键,而针对电子邮件,我想从用户ID中获得余额和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

1 个答案:

答案 0 :(得分:0)

“您可以更正此查询吗?”-也许

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`