[development] SQL question.

Gordon Heydon gordon at heydon.com.au
Fri Feb 3 05:19:02 UTC 2006


Hi,

On Thu, 2006-02-02 at 23:33 -0500, Pat Collins wrote:
> On Fri, 03 Feb 2006 15:17:39 +1100, Gordon Heydon <gordon at heydon.com.au> wrote :
> 
> > Hi,
> > 
> > I have been trying to work out a small sql issue, and I was wondering if
> > someone might be able to help me.
> > 
> > Basically I have 2 tables and I was to do a left join and pull out all
> > rows which has a value in the right hand table or doesn't exist.
> > 
> > eg.
> > 
> > SELECT a.a, a.b, b.a, b.c FROM a LEFT JOIN b ON a.a = b.a WHERE b.c =
> > 'A';
> > 
> 
> Your where clause is going to limit you to only rows where b.c = 'A'. 

I thought that this was the case.

> 
> > So basically I want it to return.
> > 
> > a	b	a	c
> > 1	1	null	null
> > 2	2	2	A
> > 
> 
> So you will probably want to add 'OR b.a is null' (or however you have the
> lack of value defined) to your WHERE above.

Yes the 'is null' fixed this for me.

Thanks so much.

Gordon.



More information about the development mailing list