Thanks for helping! I'm a newbie in SQL.
I trying to retrieve users for whom the value of column offers__c is equal to 'a' but can also be equal to 'a' and 'w' and / or 'x' and / or 'y' and / or 'z' and / or empty ('').
Each user can have multiple rows (with 'a', 'w', 'x', 'y', 'z', '') with a non-unique common id. (They must have 'a' anyway.)
I would like to retrieve the rows if they exist, but no others.
For example: if a user has multiples rows with a column equal to 'a' and (an other row with) 'w' and (an other row with) 'p', I do not want to retrieve it.
SELECT customerAccount__c,
offers__c,
Id
FROM Table1
WHERE customerAccount__c IN (
SELECT customerAccount__c
FROM Table1
WHERE offers__c = 'a' OR ( offers__c = 'a' AND (
offers__c = 'w'
OR offers__c = 'x'
OR offers__c = 'y'
OR offers__c = 'z'
OR offers__c = ''
)
)
)
With this query I also get value like 'p' or 'r'. I would like to exclude other values that do not match the one's I requested.
EDIT:
Table1:
customerAccount__c offers__c Id
- - -
1 'a' 0015800001RzCebAAF
1 'w' ...
1 'x'
3 'y'
2 'a'
2 'w'
3 'z'
3 'a'
4 'a'
5 'a'
5 'w'
5 'p'
OUTPUT:
customerAccount__c offers__c Id
- - -
1 'a' a0G5808300xWGxQEAG
1 'w' a0G5737300xWGxqEAG
1 'x' a0G5809990xWGxqEAG
2 'a' ...
2 'w'
3 'y'
3 'z'
3 'a'
4 'a'
5 'a' 0015800001RzCCbAAF
5 'w' 0015800002RzDAbAAF
5 'p' 0015800003REDEbAAF
For this exemple, I get offers__c (5) with 'p'. But I don't want it. I would like only the customerAccount__c (1) and exclude the (5) because of 'p'.
:note that I do not know all the different values in the table (because there is like 130+ potential values) eg. 'p', 'r', 'g' etc..
EXPECTED OUTPUT:
customerAccount__c offers__c Id
- - -
1 'a'
1 'w'
1 'x'
2 'a' ...
2 'w'
3 'y'
3 'z'
3 'a'
4 'a'
offers__c = 'a' OR ( offers__c = 'a' AND ( ...is redundant.a OR (a AND (b OR c OR d OR e))is equivalent toa.