Suppose I’m trying to construct a SQL query to find all people that haven’t made a sale since 6/1/2012 and I have 2 tables:
UserID FirstName LastName
1000 Ted Ting
1001 Sally Song
1002 Adam Apple
UserID SalesDate
1000 8/1/2012
1000 6/12/2012
1000 6/11/2012
1000 5/3/2012
1001 3/1/2012
1001 5/30/2012
1002 6/15/2012
1002 5/1/2011
The result of this query would contain columns:
UserID FirstName LastName LastSalesDate
1001 Sally Song 5/30/2012
Notice that this just returns Sally’s latest sale, not all sales that were before the date (it doesn’t show the sale on 3/1/2012). What is the right SQL query to get this?
1 Answer