Hello Experts!
I am in need of some query related tips from you J . By reading the given below table structures can you please suggest me the best way to write the query for retrieving results faster..
The following example is not the real data structure with me, but it is a copy with the original one.
I have a table which contains the name of the students and their location. Please see the below structure.
Student Master Table
Student_Id | Name | Continent | Country | Region | Province |
1 | Adriana | Europe | NL | NL1 | Utrecht |
2 | Leo | Europe | NL | NL2 | Gelderland |
3 | Steff | North America | USA | Idaho | Boise |
4 | Catherine | South America | Brazil | Federal District | Brasilia |
5 | Alan | Europe | Germany | Bavaria | Munich |
6 | Herman | North America | Canada | Ontario | Toronto |
7 | Aved | Asia | India | Kerala | Calicut |
8 | Lee | Australia | Australia | New South Wales | Sydney |
9 | Akio | Asia | Japan | Toyota | Aichi |
10 | Fernando | North America | Mexico | Baja California | Mexicali |
11 | Mahendra | Asia | India | Delhi | New Delhi |
To classify the above students table based on their regions, I have another translation table which contains a classification name and the list of continent, country, region and province belongs to the classification.
Regional Classification Table
Id | Region | Continent | Country | Region | Province |
1 | Europe | Europe |
|
|
|
2 | USA | North America | USA |
|
|
3 | Latin America | South America |
|
|
|
4 | Canada & Mexico | North America | Canada |
|
|
5 | Canada & Mexico | North America | Mexico |
|
|
6 | East Asia | Asia | Japan |
|
|
7 | Australasia | Australia |
|
|
|
8 | Australasia | Oceania | New Zealand |
|
|
9 | South India | Asia | India | Kerala |
|
10 | South India | Asia | India | Tamil Nadu |
|
11 | North India | Asia | India | Delhi |
|
12 | Mumbai | Asia | India | Maharashtra | Mumbai |
Based on the above translation table I need to classify the students with the Region they are belonging to. The translation here can be done with the combination of four columns; Continent, Country, Region and Province. That means a Region can be either only a Continent or a group of Continents, or the combination(s) of Continent and Country, or combination(s) of Continent, Country and Region, or combination(s) of Continent, Country, Region and Province. So four types of combinations can be done. Can you please suggest what is the best way to join this table to Master table having millions of records of data in ti? As of now I have created 4 queries and clubbed them with ‘Union All’ clause.
Thanks in advance,
Nithin