来自多个表的 Oracle Select?
Oracle Select from multiple Tables?
我在 Oracle 中有多个表,它们具有相互链接的主键和外键。 table 是:
Continent
Sub-Continent
Country
Region
City
Location
每个布局的示例:
continent_id | continent_name
1 | Africa
2 | America
sub_continent_id | sub_continent_name | continent_id
A1 | Southern Africa | 1
B1 | Western Africa | 1
A2 | North America | 2
B2 | South America | 2
country_id | country_name | sub_continent_id
CAN | Canada | A2
ZA | South Africa | A1
其余部分继续如此:Region
、City
和 Location
。
可以看出,ID 引用了另一个 table。所以:
country_name
"Canada" 引用 sub_continent_id
"A2" 即“北
美国”。"North America" 引用 continent_id
2 即 "Americas"。
我想尝试做的是 运行 一个 SQL 查询,如果我选择了一个位置,它应该 return 来自其他 [=45] 的其余值=]秒。因此,如果我 select 一个名为 "Triange Building" 的位置,它会自动 return:
Triangle Building, New York City, New York, North America, Americas
我不确定每次 运行 收集所有这些值的查询。
我可以 运行 这样的单个查询来显示地区名称和城市名称,但不知道如何 select 来自更多表的更多值。
SELECT E.city_name NAME,D.region_name DNAME
FROM CITY E JOIN REGION D
ON (E.region_id = D.region_id);
加入所有表
SELECT E.city_name as NAME, D.region_name as DNAME, C.COUNTRY_NAME, SC.SUB_CONTINENT_NAME,
CO.CONTINENT_NAME
FROM CITY E JOIN REGION D ON E.region_id = D.region_id
JOIN COUNTRY C ON D.country_id = C.country_id
JOIN SUB-CONTINENT SC ON C.sub_continent_id = SC.sub_continent_id
JOIN CONTINENT CO ON SC.continent_id = CO.continent_id;
我在 Oracle 中有多个表,它们具有相互链接的主键和外键。 table 是:
Continent
Sub-Continent
Country
Region
City
Location
每个布局的示例:
continent_id | continent_name
1 | Africa
2 | America
sub_continent_id | sub_continent_name | continent_id
A1 | Southern Africa | 1
B1 | Western Africa | 1
A2 | North America | 2
B2 | South America | 2
country_id | country_name | sub_continent_id
CAN | Canada | A2
ZA | South Africa | A1
其余部分继续如此:Region
、City
和 Location
。
可以看出,ID 引用了另一个 table。所以:
country_name
"Canada" 引用 sub_continent_id
"A2" 即“北
美国”。"North America" 引用 continent_id
2 即 "Americas"。
我想尝试做的是 运行 一个 SQL 查询,如果我选择了一个位置,它应该 return 来自其他 [=45] 的其余值=]秒。因此,如果我 select 一个名为 "Triange Building" 的位置,它会自动 return:
Triangle Building, New York City, New York, North America, Americas
我不确定每次 运行 收集所有这些值的查询。
我可以 运行 这样的单个查询来显示地区名称和城市名称,但不知道如何 select 来自更多表的更多值。
SELECT E.city_name NAME,D.region_name DNAME
FROM CITY E JOIN REGION D
ON (E.region_id = D.region_id);
加入所有表
SELECT E.city_name as NAME, D.region_name as DNAME, C.COUNTRY_NAME, SC.SUB_CONTINENT_NAME,
CO.CONTINENT_NAME
FROM CITY E JOIN REGION D ON E.region_id = D.region_id
JOIN COUNTRY C ON D.country_id = C.country_id
JOIN SUB-CONTINENT SC ON C.sub_continent_id = SC.sub_continent_id
JOIN CONTINENT CO ON SC.continent_id = CO.continent_id;