tags:

views:

28

answers:

1
Table1  
F1   F2   F3   F4 
ab1  bc1  de1  5
ab2  bc2  de2  6
ab3  bc3  de3  0

Table2 
F21 F22  F23
5   five  d
6   six   e

Table3 
f31 
ab1
ab2
ab3


 select a.f1 a.f2 b.f22  from Table1 as a Table2 as b Table3 as c 
 where a.f1 = c.f31  and a.f4 = b.f21

I am looking for result

ab1 bc1 five

ab2 bc2 sex

ab3 bc3 ""

I dont know how to ask this . But my question is if a.f4 = b.f21 is not matcheed which means

0 is not there in table 3 but still i want to result with empty value .. how to acheive this ?

+1  A: 

As mentioned in the comments, you should use a LEFT JOIN. This does require rewriting your query a bit.

LEFT OUTER JOIN - Based on the two tables specified in the join clause, all data is returned from the left table. On the right table, the matching data is returned in addition to NULL values where a record exists in the left table, but not in the right table. Another item to keep in mind is that the LEFT and RIGHT OUTER JOIN logic is opposite of one another. So you can change either the order of the tables in the specific join statement or change the JOIN from left to right or vice versa and get the same results.

  SELECT  a.f1 a.f2 b.f22  
  FROM    Table1 as a 
          LEFT OUTER JOIN Table2 as b ON a.f4 = b.f21
          LEFT OUTER JOIN Table3 as c ON c.f31 = a.f1
Lieven