ManikandanKannan ManikandanKannan - 2 years ago 75
SQL Question

Database left outer join with a base table

I have 3 tables A, B, C with the data as follows

Table A

C1 C2
100 X
200 Y
300 z

Table B

C1 C2
100 bb
300 bb1

Table C

C1 C2
200 cc
300 cc1

I want a query which can out put as follows; The count of records in the result should be same as the count of records in A.

100 X 100 bb null null
200 y null null 200 cc
300 z 300 bb1 300 cc1

Note: All the tables have one-one relationship and 3 tables are just given for example. This can be any number of tables.

Answer Source

Try this:

FROM tableA a
LEFT JOIN tableB b ON a.c1 = b.c1
LEFT JOIN tableC c ON a.c1 = c.c1 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download