Pull multiple fields from table B where a specific value from Table A is not in Table B
0
votes
1
answer
32
views
SQL Newbie here. I have a question about pulling multiple fields from a database when one value is not in another table. I have two tables:
- "Contact" table - contains all of our contact information such as their email address, contact creation date, department, job, etc. This is considered our master table.
- "Event" table - contains information regarding a contact and their email activity such as their email address, email delivery status, email create date, etc.
The db uses the email address as the joining key. I don't have the privileges (due to work restrictions) to add a new PK.
The task is to find all contacts in the Contact table that are not in the Event table, and pull their email address AND their contact creation date. The Event table does not have the contact creation date. When I select only the email address it works fine, but when I try to add in the second field (create date), it gives me an error.
The query I'm using is below. Any help is appreciated!
SELECT e.recipient, c.contactProperty_createdate
FROM Event as e
WHERE NOT EXISTS
(SELECT c.emailAddress, c.contactProperty_createdate
FROM Contact as c
WHERE c.emailAddress = e.recipient);
Asked by Christopher Taylor ENG
(1 rep)
Dec 17, 2018, 08:13 PM
Last activity: Dec 17, 2018, 08:23 PM
Last activity: Dec 17, 2018, 08:23 PM