2016-02-29 79 views
0

如何返回AccountDescription的唯一記錄?我知道如何使用distinct,但我不確定如何在這種情況下應用它。在MySQL中選擇獨特

SELECT 
     Contacts.FirstName, 
     Contacts.LastName, 
     Account.AccountType, 
     Account.AccountDescription 
    FROM Contacts 
    INNER JOIN Account 
     ON Contacts.UserID = Account.AccountID 
    WHERE UserAccountType LIKE '%TEST%' 
    AND AccountType = 'trial' 

基本上,我需要抓住所有的獨特AccountDescription因爲有許多具有相同AccountDescription接觸。

我現在有返回:

AccountType : Trial , AccountDescription : test1 
AccountType : Trial , AccountDescription : test2 
AccountType : Trial , AccountDescription : test1 

我需要抓住的唯一AccountDescription

+0

解決它自己沒有批評意圖,但我真的很好奇你是什麼意思 - 「知道h因爲這幾乎是最基本和最初使用的人們熟悉的。 – Uueerdo

回答

0

嘗試此查詢:

SELECT DISTINCT Contacts.FirstName, Contacts.LastName, 
Account.AccountType, Account.AccountDescription 
FROM Contacts INNER JOIN Account ON Contacts.UserID = Account.AccountID 
WHERE UserAccountType LIKE '%TEST%' AND AccountType = 'trial' 
0

我用GROUP BY AccountDescription;

+0

請注意,如果您按AccountDescription進行分組,則基本上將所有數據丟棄在其他三個字段中,並且通常沒有理由給它們;你會得到的價值是_officially_不可預測......特別是如果AccountDescription在它自己​​的表中不是唯一的。 – Uueerdo