0

Possible Duplicate:
SQL - find records from one table which don’t exist in another

I have the following (simplified) schema in MySQL:

simplified schema

An arrow indicates a one (non-arrow side) to many (arrow side) relationship.

I want to determine, for which delivery_zone_weeks, does a customer not have a weekly_order.

Community
  • 1
  • 1
Toxygene
  • 487
  • 3
  • 10

1 Answers1

0

It is difficult to understand fully without structures, sample data and expected result, but seems to be risking it a bit you need

SELECT * FROM DELIVERY_ZONE_WEEK WHERE ID_DELIVERY_ZONE_WEEK NOT IN
(SELECT WO.ID_DELIVERY_ZONE_WEEK FROM CUSTOMER C
JOIN SHIPPING_ADDRESS SA
    ON C.ID_CUSTOMER = SA.ID_CUSTOMER
JOIN WEEKLY_ORDER WO
    ON SA.ID_SHIPPING = WO.ID_SHIPPING
WHERE C.ID_CUSTOMER = @ID_CUSTOMER)
ronpy
  • 262
  • 1
  • 13