title: SQL Join by Date Range
body: <p>I'm having a bit of a frustrating time with a SQL query and could really use the help. Basically, I have a table of customer interactions (sales visits), which has a <code>customer_id</code>, a <code>sales_location</code> and an <code>visit_date</code>. I have a separate table that has orders resulting from that visit. Some visits resulted in zero orders while others resulted in multiple orders. The order table has the <code>customer_id</code> and <code>order_date</code> with each row representing a distinct order.</p>
  
  <p>I need to create a merged table that has a row for every order or visit linked to the <code>sales_location</code> where the order originated from. Basically, the tables have been designed poorly and we need to understand which sales locations are producing a lot of orders per customer visit.</p>
  
  <p>What I need to do, and the piece I'm struggling with, is to use SQL to implicitly figure out, based on the <code>order_date</code>, which interaction it was associated with for that <code>customer_id</code>. For example, let's say we interacted with customer #463 in Reno and then in Dallas, there would be two interactions on two dates. We may have had 3 orders as a result of the Reno trip and one order as a result of the Dallas trip (or none). I need to use the dates of the orders to figure out which sales location the order came from. What is the best way to do this?</p>