views:

23

answers:

2

I have a query:

Select a.Col1,b.Col2
From a
Left Join B b ON a.C = b.C
Where b.D ='someValue'

But when right side is null, I don't get record , so Left Join doesn't work.

Do you know how to change this query to correct query ?

A: 

The query returns nothing when the right side is null due to your where clause. If there's no table b referred, your where clause will not be met.

I'm not quite sure how to correct your query. In my opinion, this query insinuates the link between both tables is required and thus your result is correct, semantically.

Anzeo
+5  A: 

Move the additional join condition into the on clause:

Select a.Col1,b.Col2
From a
Left Join B b ON a.C = b.C and b.D = 'someValue'
Damien_The_Unbeliever
Yes, or use condition `WHERE b.D = 'someValue' OR b.D IS NULL`
Unreason