Advanced SQL question: NOT EXISTS

From: JamesF5088 <jamesf5088_at_aol.com>
Date: 1995/05/23
Message-ID: <3psubg$or6_at_newsbf02.news.aol.com>#1/1


From the following tables I would like to find the SALESPERSON who has an ORDER with every CUSTOMER ( David in the example) using NOT EXISTS.

Tables:
SALESPERSON
    salesperson char(10)

ORDER
    salesperson char(10)
    customer char(10)

CUSTOMER     
    customer      char(10)

The tables are poplulated as follows:
SALESPERSON

      David
      Susan          
      Robert

ORDER

   David,  Customer1
   David,  Customer2
   Susan, Customer1

CUSTOMER
    Customer1
    Customer2

I've tried the following SELECT statement with no success.

select salesperson
from salesperson
where not exists

   ( select *

     from order 
     where not exists
           ( select * from customer
             where customer.customer = order.customer
             and salesperson.salesperson = order.salesperson
           )

   );

Thank you in advance for all replies to this question. Jim Received on Tue May 23 1995 - 00:00:00 CEST

Original text of this message