2013-10-08 127 views

回答

1

首先查詢:

取得目前所有客戶端來賓

SELECT c.* 
FROM client c 
WHERE EXISTS(
    SELECT 'X' 
    FROM guest g 
    WHERE c.client_idNum = g.guest_icNum 
) 

或者:

SELECT c.* 
FROM client c 
JOIN guest g 
ON c.client_idNum = g.guest_icNum 

第二個查詢:

獲取客人不存在的所有客戶端:

SELECT c.* 
FROM client c 
WHERE NOT EXISTS(
    SELECT 'X' 
    FROM guest g 
    WHERE c.client_idNum = g.guest_icNum 
) 

或者:

SELECT c.* 
FROM client c 
LEFT OUTER JOIN guest g 
ON c.client_idNum = g.guest_icNum 
WHERE g.guest_icNum IS NULL 
相關問題