Home » SQL & PL/SQL » SQL & PL/SQL » query
query [message #11127] Mon, 08 March 2004 13:37 Go to next message
Sril
Messages: 13
Registered: November 2002
Junior Member
Hi,

I have 2 tables  supplier & parts.

Supplier

SUPPLIERCODE     PARTNO
------------ ----------
           1         34
           2         12
           3         34
           4         12
           2         45
           5         45
           2         67
           1         45
           2         23
           4         45
           2         34

SUPPLIERCODE     PARTNO
------------ ----------
           2         56
           6         12
           2         78

Parts

    PARTNO NAME
---------- --------------------
        12 pen
        23 pencil
        34 eraser
        45 scale
        56 compass
        67 sharpener
        78 pencil box

The query is to retrieve the supplier who supplied all the parts.In my case, supplier 2 has supplied all parts.  Is it possible to write it without using count function?

Thanks in advance.

Sril

 
Re: query [message #11129 is a reply to message #11127] Mon, 08 March 2004 15:13 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Using COUNT would be more efficient, but here's one way to do it without count:

sql>select distinct suppliercode
  2    from supplier
  3   where suppliercode not in 
  4           (select suppliercode
  5              from (select sp.suppliercode, s.suppliercode match
  6                      from (select distinct 
  7                                   s.suppliercode, p.partno 
  8                              from supplier s, parts p) sp,
  9                           supplier s
 10                     where s.suppliercode (+)= sp.suppliercode
 11                       and s.partno (+)= sp.partno)
 12             where match is null);
 
SUPPLIERCODE
------------
           2
 
1 row selected.
Re: query [message #11130 is a reply to message #11129] Mon, 08 March 2004 16:05 Go to previous message
Sril
Messages: 13
Registered: November 2002
Junior Member
Thanks for the immediate response!!! It works really well.

Sril
Previous Topic: compare user objects
Next Topic: inverse query
Goto Forum:
  


Current Time: Fri Apr 26 03:05:41 CDT 2024