mysql - SQL数据重复

标签 mysql sql

this is how my query displays data relationship of tables

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'   

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

最佳答案

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 将仅提供不同的记录。

关于mysql - SQL数据重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58957363/

相关文章:

mysql - 我可以使用 SQL 显示基于列值的自定义文本吗?

mysql - 使用 MySQL Like 搜索带符号的数字

mysql - 用户数据和更改日志的哪种布局最有效且存储消耗更少?

python - 如何按最新子项中的列过滤 sqlalchemy 查询

mysql - 如何在 Sequelize 和 Mysql 中编写此查询

sql - 如何从 Pandas 表中的先前加载中选择大于文件中存储的最大时间戳的记录

mysql - 自连接查询 : how to return children and parent row?

javascript - 多选复选框ajax表过滤器

php - 如何在php codeIgniter中更新相同的字段但不同的表

php - Laravel 5.2 中的 MySQL 摘要查询