Re: SQL question

From: James A. Walker <JAWALKER_at_PBIS.COM>
Date: 1996/07/26
Message-ID: <4t98mg$k90_at_newshost.ptes.com>#1/1


See if this get the results you are looking for. I have made the assumption that duplicate id_b, attr_b pairs are not allowed or at least not significant.

SQL> accept id_b prompt 'Enter Tab_B id: ' SQL> select id_a
  2 from tab_a
  3 where attr_a in (select attr_b

  4                   from tab_b
  5                   where id_b = &id_b)
  6 group by id_a
  7 having count(distinct attr_a) =
  8 (select count(distinct attr_b) from tab_b where id_b = &id_b)   9 /

ID-A



512

Hope this helps!

In article <6DCyYJnJNtB_at_hit-mike.hit.handshake.de>, mike_at_hit.handshake.de says...

>I wonder if there is a way to solve the following problem by using a SQL
>query:
>
>There are two tables (TAB_A, TAB_B) containing ID numbers and attributes.
>I want to select those ID_As in table A where all attributes of a given
>ID_B in table B are contained in the set of A. In the following example
>would ID_A = 512 returned for ID_B = 1. ID_B = 25 doesn't match because no
>set in A contains *all* the attributes of set 25 in B.
>To solve this query with a single SQL statement would by nice, but
>probably I have to code it in PL/SQL.
>
>TAB_A TAB_B
>=============== ===============
>ID_A ATTR_A ID_B ATTR_B
>--------------- ---------------
>512 1 1 1
>512 4 1 4
>512 5 1 5
>512 17 13 1
>539 2 . .
>. . 25 1
>568 5 25 5
>568 7 25 12
>568 12 43 5
>. . . .
>. .
>



James A. Walker
Pacific Bell Information Services
510.806.4764
jawalker_at_pbis.com Received on Fri Jul 26 1996 - 00:00:00 CEST

Original text of this message