首页 > 解决方案 > SQL 数据复制

问题描述

这就是我的查询显示数据的方式表的关系

sql查询

SELECT `user`.`email`, 
    `user`.`passwrd`, 
    `user`.`status`,
    `useraccounts`.`Balance`, 
    `useraccounts`.`AccountID`, `accounts`.`AccountNo`,
    wallet.Server_typ,wallet.DateBought,
    wallet.LastDate,
    wallet.Profit,
    withdraws.walletAdrs,
    withdraws.Amount,
    withdraws.status AS WDStatus, 
    withdraws.message, 
    withdraws.Date 
FROM `user`
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email` 
LEFT JOIN `accounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID` 
LEFT JOIN wallet ON user.email = wallet.email 
LEFT JOIN withdraws ON user.email = withdraws.email 
WHERE user.type = 'user'   

这是我的查询,它工作正常,但有很多针对电子邮件地址的记录。因此,我的电子邮件会重复。每当我打电话只是电子邮件重复记录来。我只想要一封电子邮件。提前致谢

标签: mysqlsql

解决方案


SELECT DISTINCT `user`.`email`, `user`.`passwrd`, `user`.`status`,`useraccounts`.`Balance`, `useraccounts`.`AccountID`, `accounts`.`AccountNo`,wallet.Server_typ,wallet.DateBought,wallet.LastDate,wallet.Profit,withdraws.walletAdrs,withdraws.Amount,withdraws.status AS WDStatus, withdraws.message, withdraws.Date 
FROM `user` 
LEFT JOIN `useraccounts` ON `user`.`email` = `useraccounts`.`email` 
LEFT JOIN `accounts` ON `accounts`.`AccountID` = `useraccounts`.`AccountID` 
LEFT JOIN wallet ON user.email = wallet.email 
LEFT JOIN withdraws ON user.email = withdraws.email
WHERE user.type = 'user'

使用 DISTINCT 将只提供不同的记录。


推荐阅读