vendredi 8 mai 2015

Need to get data from multiple tables with same foreign key

I have table-1 with

InjID - (PK) and Name

Table 2 with Tid (RefK) ever InjId(Table1) and Name

Table 3 with ID (RefK) refer again InjID (Table1) and Name

There is no link between Table 2 and Table 3.

I have data as follows:

Table1

________________
InjID     Name
----------------
1         xxxx
2         bbbb
3         cccc
4         yyyy

Table 2

--------------
TID      Name
--------------
1        A3434
1        R5678
2        G6789

and Table 3

-------------
ID     Name
-------------
2      89T
2      78P
3      66J

I want the results like this:

--------------------------
injid    Table1-name Table2-name table3-name
--------------------------------------------
1         xxxx        A3434        null
1         xxxx        R5678        null 
2         bbbb        G6789        89T
2         bbbb        null         78P
3         cccc        null         66J
4         yyyy        null         null

Aucun commentaire:

Enregistrer un commentaire