Re: A SQL question

From: Jurij Modic <jmodic_at_src.si>
Date: Wed, 30 Dec 1998 22:19:00 GMT
Message-ID: <368a9a77.14299043_at_news.siol.net>


On Wed, 30 Dec 1998 18:48:23 +0800, Donald Yeh <u7844131_at_ms17.hinet.net> wrote:

>This is a multi-part message in MIME format.
>--------------9C5EB73D22A4E780CD948EBA
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit
>
>I've two tables, the column c1 is Primary key in table Table-1,
> and the column c01 + c02 is primary key in table
>Table-2,
> and c01 is also reference to Table-1.c1
>
><Table-1> <TAble2>
>c1 c01 c02
>---- ---- ----
>A A 1
>B B 1
>C C 1
>D A 2
>E A 3
>
>I want the result like below
>
>== == == == == ==
>A 1 A 2 A 3
>B 1 B B
>C 1 (or) C (or) C
>D D D
>E E E
>
>How do I write the SQL command??

If I understand correctly what you want to achive, here is one of the possible solutions (on your example's data):

SQL> SELECT t1.c1, MIN(t2.c02) FROM table_1 t1, table_2 t2   2 WHERE t1.c1 = t2.c01(+)
  3 GROUP BY t1.c1;

C MIN(T2.C02)
- -----------

A           1
B           1
C           1

D
E

HTH,
Jurij Modic <jmodic_at_src.si>
Certified Oracle7 DBA (OCP)



The above opinions are mine and do not represent any official standpoints of my employer Received on Wed Dec 30 1998 - 23:19:00 CET

Original text of this message