I have a database that has multiple tables to track customers and our interactions with them, among other things. I’m creating a report using PHP that should display all customers that have an open status and don’t have an interaction logged in the pas 2 weeks. I was trying to do a query, then while processing those results it would run another query based on that, but it was very slow and I couldn’t get it to work correctly. I think the JOIN function is my answer, but I’m not entirely sure how to implement it.
my tables have these fields:
customers: customer_id
customers_marketing_options: customer_id, status
customer_interactions: customer_id, created_on (yyyy-mm-dd hh:mm:ss)
right now, I have it selecting all customers that have an open status. Then with those results, I select all interactions with that customer id, created_on being at most 2 weeks prior, sorting that by the created_on date and selecting the top row (most recent interaction). however, that returns the interaction for customers that have a warm status. However, it doesn’t check to see if they have an interaction in the past 2 weeks.
This probably sounds confusing, however any help or guidance would be appreciated.
1 Answer