Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have 2 tables Table1 and Table2.
Table1 have (A,B,C) columns. Table2 have (A,B,D).
Table1 Having 52 Rceords.
Table2 Having 5 records. These 5 are records are exist in Table1.

Now i want to select A,B,C,D from both tables. for non existing values it should show null.

example :

A B C D
1 10 null 25
2 10 85 null.

Please help me on this.

Regards,
Prasad
Posted

1 solution

Hi, at a guess I believe the code below should do what you require.

SQL
SELECT
    t1.A
   ,t1.B
   ,t1.C
   ,t2.D
FROM
   Table1 t1
   LEFT OUTER JOIN Table2 t2 ON
      t1.A = t2.A AND
      t1.B = t2.B


I usually use a Left Outer Join onto the table I want a null to come from

So at a guess you will have NULL in D for all but 5 results.

Hope that helps
 
Share this answer
 
Comments
fjdiewornncalwe 13-Nov-12 16:57pm    
+5. Good answer.
Rob Branaghan 13-Nov-12 17:20pm    
Thanks Marcus :)
Prasad Guduri 13-Nov-12 23:25pm    
Thank you Rob...This is what i'm looking for....!!!
Rob Branaghan 14-Nov-12 6:26am    
Your welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900