I am trying to select only the rows where I have different columns of the PartnerID column. I have 1 simple table which contains 3 main columns - ID, Acct and PartnerID. I am trying to GROUP BY Acct
and then check if this Acct ID have different Partners ID in it. For example if I have those rows:
ID Acct PartnerID OperType
3 5 4 2
4 5 3 2
5 6 6 2
6 6 6 2
I want to be able to select the Acct with ID 5 as it contains different Partners ID's, but not selecting the Acct 6 as it has the same Partners ID.
So I tried this code, but It is not working as I am not selecting only the Acct's I need:
SELECT Acct
FROM `Operations`
WHERE OperType = 2
GROUP BY Acct, PartnerID
ORDER BY `Acct` ASC
I also tried this, but I am geting empty result:
SELECT Acct
FROM `Operations`
WHERE OperType = 2
GROUP BY Acct, PartnerID
HAVING COUNT(DISTINCT PartnerID) > 1
ORDER BY `Acct` ASC