Find dates in one table but not another

Johnny C

Registered User.
Local time
Today, 05:32
Joined
Feb 17, 2014
Messages
19
Hi
Sorry if this is a very dumb question

I've got two tables, both are indexed by customer ID, with a series of dates against the customer ID.
One has a list of all dates a customer was visited, the other is a list of dates where activity happened on the customer account

I want to get a list of the dates when the customer was visited but where no activity happened on the customer account,
i.e. where there is a customer visit date on the customer visit table but no record for that date on the activity table.

How do I do that? I can find all dates where was a date was on both tables, but I've no idea how to find where its on one but not the other

Cheers
 
Try the LEFT/RIGHT JOIN, you can use the Is Null option to filter the result. Something like,
Code:
SELECT tblVisit.CustomerID, tblVisit.DateOfVisit 
FROM tblVisit LEFT JOIN tblActivity ON tblVisit.CustomerID = tblActivity.CustomerID
WHERE tblActivity.DateOfActivity Is Null;
 
Thanks Paul.

I was hoping to give SQL a swerve but I guess there comes a time when it's the only way.
 

Users who are viewing this thread

Back
Top Bottom