Sorry , maybe it's trivial but I can't find a way to do this :
table customers
- customer_id
- customer_email
- customer_newsletter (1=yes/0=no)
table orders
- order_id
- customer_id
- order_status (1=ok/0=no_ok)
Each customer can have zero, one or many orders.
I'm trying to make a query to get all the emails of the persons who are :
1/ not yet customers, they have never placed an order but they want to receive my newsletter
or
2/ already customers (one or more orders in the corresponding table). But only if the status of their latest order is OK (I don't want to send the newsletter to problematic customers)
I've tried several things based on subqueries with MAX function but can't find the good formulation
Any advice ? thanks in advance