Re: A newbie question on SQL...

From: Keith Thompson <mcdoo_at_worldgate.edmonton.ab.ca>
Date: 16 Feb 1995 05:26:08 GMT
Message-ID: <3hunlg$3lj_at_scanner.worldgate.edmonton.ab.ca>


In article <3hrjv7$p16_at_amdint.amd.com>, Chung Ley <chung.ley_at_amd.com> says:

>Table A is my master table; Table B is the detail and Table C
>is just attribute data....
>
>For each record in Table A, there may or may not be any records in
>Table B. I was trying to run a outer-join query, and if there are
>record(s) in Table B, I want to use the most recent one:
>
> My query looks like this:
>
> select a.column1, a.column2, b.column1, b.column2,
> c.full_name
> from TableA a, TableB b, TableC c
> where a.key1 (+)= b.key1
> and a.key2 (+)= b.key2
> and b.latest_flag = 'Y'
> and b.userid = c.userid;
>
>Well, it didn't work like I expected....

You have your outer join symbol on the wrong table. Your statement should read

   select a.column1, a.column2, b.column1, b.column2,

          c.full_name
     from TableA a, TableB b, TableC c
    where a.key1 = b.key1 (+)
      and a.key2 = b.key2 (+)
      and b.latest_flag = 'Y'
      and b.userid  = c.userid;

Remember to put the outer join symbol on the table name which may not contain any matching records.

Hope this helps.
Keith *<:o) Received on Thu Feb 16 1995 - 06:26:08 CET

Original text of this message