我在oracle数据库中有4个表:学生,国家,省,地区
---------------------------------------------------------------------------
student : student_id,student_name,country_id,province_id,district_id
country : country_id, country_name
province : country_id, province_id, province_name
district : country_id, province_id, district_id, district_name
---------------------------------------------------------------------------
我想使用连接显示以下字段:student_name,country_name,province_name,district_name
答案 0 :(得分:0)
您需要一个简单的INNER JOIN:
select s.student_name, c.country_name, p.province_name, d.district_name
from student s
join country c on s.country_id = c.country_id
join province p on p.province_id = s.province_id
join district d on d.district_id = s.district_id;
假设country_id
,province_id
和district_id
是相应表中的主键。
答案 1 :(得分:0)
考虑这是您的主表。 如果是学生,则使用LEFT Join,要加入Tabels:
SELECT S.student_name,
C.country_name,
P.province_name,
D.district_name
FROM student S LEFT JOIN country C ON S.country_id=C.country_id
LEFT JOIN province P S.province_id=P.province_id
LEFT JOIN district D S.district_id=D.district_id