|
---- A table can be joined to itself in a self-join
tblWorld |
CountryID |
Name |
ContinentID |
1 |
Vijay |
3 |
2 |
USA |
4 |
3 |
Asia |
NULL |
4 |
N.America |
NULL |
5 |
Nepal |
3 |
6 |
Canada |
4 |
SELECT c1.name AS Continent, c2.Name Country
FROM tblWorld c1
JOIN tblWorld c2
ON c1.CountryID = c2.ContinentID
Output |
Continent |
Country |
Asia |
India |
Asia |
Nepal |
N.America |
USA |
N.America |
Canada |
|