ali
ali

Reputation: 19

SQL Data Duplication

this is how my query displays datarelationship of tables

sql query

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'   

This is my query, it works fine but there are many records against an email address. Because of this, my email gets duplicate. whenever i call just email duplicate records come. I just want one email.thanks in advance

Upvotes: 0

Views: 82

Answers (1)

Yakir Malka
Yakir Malka

Reputation: 308

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'

Using DISTINCT will provide only distinct records.

Upvotes: 1

Related Questions