Hi there,
An SQL statement I have written in Access Query does not do what I would like it to do, and I wonder if you can help.
I have tables that can be linked via an identifier, with each table containing potentially multiple records per each ID number.
Here is some sample data from the 2 tables:
SolicitCode Table:
ContactID
SolicitCode
1261
Postal opt out
1261
Email opt in
7592
Postal opt out
9000
Email opt out
9000
EverydayHero opt In
9000
Postal opt out
9000
Telephone opt out
9500
Email Opt In
Attribute Table:
ContactID AttributeCode
1261
Email opt in
1261
Postal opt out
7592
Email opt in
7592
Email opt in
7592
Postal opt in
7592
Postal opt in
7592
Postal opt in
7592
Postal opt in
7592
Telephone opt in
7592
Telephone opt in
9000
Email opt out
9000
Postal opt out
9000
Telephone opt out
What I am intending to do is to create a dataset that selects the ContactID and SolicitCode from the SolicitCode table where the SolicitCode of the contact does NOT match the AttributeCode.
In other words, I want it to create this dataset:
ContactID
Solicit Code
7592
Postal opt out
9000
EverydayHero opt In
9500
Email Opt In
My current code is as follows:
SELECT SolicitCode.*
FROM SolicitCode LEFT JOIN Attribute ON SolicitCode.ContactID = Attribute.ContactID
WHERE SolicitCode.SolicitCode <> Attribute.AttributeCode;
However, this returns the following dataset! :
ContactID SolicitCode 1261 Postal opt out 1261 Email opt in 7592 Postal opt out 7592 Postal opt out 7592 Postal opt out 7592 Postal opt out 7592 Postal opt out 7592 Postal opt out 7592 Postal opt out 9000 Email opt out 9000 Email opt out 9000 EverydayHero opt In 9000 EverydayHero opt In 9000 EverydayHero opt In 9000 Postal opt out 9000 Postal opt out 9000 Telephone opt out 9000 Telephone opt out
I think its because as it runs the query, for each contact, it checks whether the statement is true or not for EACH LINE per ID match, not for the ENTIRE contact record.
I'm sure its something very simple, any help would be massively appreciated!!!
Antonio