从两个不同的表中选择子句

时间:2014-04-21 05:22:00

标签: sql sqlplus

SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
FROM DEPARTMENT,PROJECT
WHERE DEPARTMENT.D# <> PROJECT.D#;

当这段代码在SQL plus中运行时,会出现很多重复输出,我的输出应该是 只有一次。

2 个答案:

答案 0 :(得分:0)

不确定这是否是您想要的,但如果您只想要那些没有任何项目的部门

SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
   FROM DEPARTMENT
      WHERE DEPARTMENT.D# not in (select PROJECT.D# from project);

希望它有助于

Vishad

答案 1 :(得分:0)

用作

SELECT DEPARTMENT.D#,DEPARTMENT.DNAME,DEPARTMENT.MANAGER#
  FROM DEPARTMENT,PROJECT
  WHERE DEPARTMENT.D# != PROJECT.D#;