SQL中EXISTS的用法

http://www.cnblogs.com/fredlau/articles/993829.html


Select deptno From dept 
Where Not Exists 
(
    Select 1 From emp 
    Where dept.deptno = emp.deptno
);

    DEPTNO
----------
        40

Select deptno From dept 
Where Exists 
(
    Select 1 From emp 
    Where dept.deptno = emp.deptno
);

    DEPTNO
----------
        10
        20
        30


Select deptno From dept 
Where Not Exists 
(
    Select 1 From emp Where SAL < 1000 
    And dept.deptno = emp.deptno
);

    DEPTNO
----------
        40
        10

你可能感兴趣的:(html,sql)