Oracle 使用sql联接返回数据,但不返回其他查询
用SQL编写一个查询,显示国家、城市和在那里运行的部门的名称。当我使用HR模式(可用图表)为上述问题编写查询时。第一个查询没有返回任何结果Oracle 使用sql联接返回数据,但不返回其他查询,oracle,join,Oracle,Join,用SQL编写一个查询,显示国家、城市和在那里运行的部门的名称。当我使用HR模式(可用图表)为上述问题编写查询时。第一个查询没有返回任何结果 1st Query: select country_name,city, department_name from HR.COUNTRIES c, HR.Locations l, HR.DEpartments d where c.COUNTRY_ID = l.country_id and d.DEPARTMENT_ID=l.location_id; 第二
1st Query:
select country_name,city, department_name
from HR.COUNTRIES c, HR.Locations l, HR.DEpartments d
where c.COUNTRY_ID = l.country_id
and d.DEPARTMENT_ID=l.location_id;
第二个查询没有返回结果
select country_name,city,department_name
from HR.COUNTRIES c join HR.LOCATIONS l on c.COUNTRY_ID =l.country_id
join HR.DEPARTMENTS d on l.location_id=d.location_id;
为什么第一个查询不起作用?谢谢您的时间。您的最后一个条件是错误的。一个
部门
有一个位置\u id
你应该用来加入位置
:
SELECY country_name, city, department_name
FROM hr.countries c, hr.Locations l, hr.departments d
WHERE c.country_id = l.country_id AND
d.location_id = l.location_id;
-- Here--^
请注意,顺便说一下,隐式联接(在from
子句中有多个表)有点过时,建议您使用显式join
子句:
SELECY country_name, city, department_name
FROM hr.countries c
JOIN hr.Locations l ON c.country_id = l.country_id
JOIN hr.departments d ON d.location_id = l.location_id;
你最后的条件是错误的。一个
部门
有一个位置\u id
你应该用来加入位置
:
SELECY country_name, city, department_name
FROM hr.countries c, hr.Locations l, hr.departments d
WHERE c.country_id = l.country_id AND
d.location_id = l.location_id;
-- Here--^
请注意,顺便说一下,隐式联接(在from
子句中有多个表)有点过时,建议您使用显式join
子句:
SELECY country_name, city, department_name
FROM hr.countries c
JOIN hr.Locations l ON c.country_id = l.country_id
JOIN hr.departments d ON d.location_id = l.location_id;
在最佳状态下复制粘贴..感谢关于显式连接的提示。在最佳状态下复制粘贴..感谢关于显式连接的提示。