0

I was wondering if there is an easy way of joining these two tables.

Table1

Name FromCountryID ToCountryID
------------------------------
sam         1          2    
lee         3          4
john        2          1

Table2:

CountryID   CountryName
1           USA
2           UK
3           Canada
4           Nepal
Sandeep Maharjan
  • 124
  • 3
  • 15

2 Answers2

1

You need to join the same table twice with different alias names

select t1.name, 
       fromTab.countryName as FromCountry,
       toTab.countryName as ToCountry
from table1 t1
left join table2 fromTab on fromTab.countryId = t1.fromCountryId
left join table2 toTab on toTab.countryId = t1.toCountryId
juergen d
  • 201,996
  • 37
  • 293
  • 362
0
 SELECT * FROM  Table1 INNER JOIN Table2 ON Table2.CountryID = Table1.FromCountryID
Gayathri Rajan
  • 369
  • 1
  • 6
  • 18