Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i came across requirement of multiple foreign keys in a table
referencing the same primary key another table.
Table structure is as follows:
Table Name
Quote:
File_Master

file_id
file_no
from_Designation_id
to_Designation_id

Table Name
Quote:
Designation_Master

Designation_id
Designation_name

File_Master has multiple foreign keys(from_Designation_id,to_Designation_id) which reference Designation_Master Designation_id(pk) .

Now can anyone please help me to join these above two table as follows
file_id, file_no, from_Designation, to_Designation
Posted

1 solution

Try

SQL
SELECT file_id, file_no, DM1.Designation_name AS from_Designation, DM2.Designation_name AS to_Designation
FROM File_Master F
LEFT JOIN Designation_Master DM1 ON F.from_Designation_id = DM1.Designation_id
LEFT JOIN Designation_Master DM2 ON F.to_Designation_id = DM2.Designation_id
 
Share this answer
 
Comments
sahabiswarup 24-Dec-12 2:13am    
Thanks for your support..
5 from me

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