I'm very new to SQL and currently using SQL Server 2008 R2. I'm fairly certain that I need to use a join but not sure if that's possible. The goal is to return just the customer's email address based on their last visit to my store. Poking around, this is the query I started off with:
SELECT DISTINCT account
FROM [main].[dbo].[visits]
WHERE time IS NOT NULL
AND date = '2017-05-25'
This correctly returned a list of customer account numbers for a particular day from table visits
. Now I need to find the customer's email, but that is stored in a different table, custlist
.
This is where I got lost. I tried some examples found on StackExchange but couldn't quite get the join logic down.
Any help is much appreciated, thank you!
Best Answer
Assuming Account is on CustList, the following example should get you going: