View Single Post

   
  #2 (permalink)  
Old 05-10-2008, 02:02 PM
Pat
 
Posts: n/a
Default Re: SQL question on an outer join

On May 9, 8:40 pm, fergus_v...@yahoo.com wrote:
> Hello,
> Learning SQL - will appreciate any help.
> Here is the case:
>
> Two tables with 0..n relationship
> TableA TableB
> ----------- --------------
> ColA ColB
> ColA_FK
> Col_C
>
> Data
> TableA.ColA
> ====================
> 1
> 2
>
> Table B
> ColB ColA_FK Col_C
> 11 2 12345
> 12 2 99999
>
> Resultset:
>
> --------------------------------------
> ColA ColB Col_C
> --------------------------------------
> 1 - -
> 2 12 99999
>
> In case no data exists in TableB for ColA=11, 1 from TableA shows up
> in result without any data from TableB
> However, in case of 2 from ColA, we want to record from TableB with
> Col_C = 99999
>
> I can do the outer join - however, how do I limit it so it picks only
> the row with 9999?
>
> Thanks in advance.
> Fergus


select tablea.cola, tableb.colb, tableb.colc from tablea left join
tableb on tablea.cola = tableb.cola_fk where tableb.colc = 9999
Reply With Quote