Katie
Katie

Reputation: 377

Getting all records based on parent's parent

This is probably trivial but I can't seem to get it. I'd like to get all the customers of all the stores in a particular area.

select * from customers
where customer... ???
... and area = 'downtown'

Their relationship:

area - 1:M - store - 1:M - customer

Upvotes: 0

Views: 19

Answers (1)

Aaron Dietz
Aaron Dietz

Reputation: 10277

I'd just use a subquery. Assuming this is across two tables then:

SELECT *
FROM CUSTOMERS
WHERE STORE(ID) IN
    (SELECT STOREID
     FROM STORES
     WHERE AREA = DOWNTOWN)

Upvotes: 1

Related Questions