I have the 2 following tables:

`customer_transaction`

```
 customer_id| event_name  | event_date

1          | joined_rewards|2019-07-10

12         | joined_rewards|2018-07-10

17         | joined_rewards|2009-07-10

```

`visit`

```
 customer_id| visit_start| visit_end|visit_type 

1          | 2019-07-09|2019-07-11| IP

12         | 2018-06-11|2018-07-12| IP

17         | 2009-07-08|2009-07-10| EP

```

I want to know all the customers in the `customer_transaction` table that joined the rewards program between their `visits` of visit\_type = IP. So for all the visit\_types = IP, I want to know the customers who joined the rewards program during the frame of their visit period. 

In this example, my new table would have customer ids 1 and 12. 

I tried 

```
SELECT DISTINCT customer_id, event_date
INTO visit_rewards
FROM customer_transaction
WHERE event_date BETWEEN (Select customer_id, visit_start, visit_end from visit)```

```