2011-08-20 104 views
-1

我有兩個表這樣 表1問題的查詢

Unix  | Staffid 
_____________________ 
534  |  65 
342  |  34 
232  |  232 
232  |  34 

表2

Staffid | auth 
____________________ 
65  | y 
34  | y 
78  | n 
45  | y 

這樣的.. 我必須選擇那些具有STAFFID AUTH Y和其不是在這個特定的unix ..例如在特定的unix 232我可以選擇65但不是34 ...我需要所有unix值。

+0

HTML表? (因爲標題是jQuery)或數據庫表? (mysql標籤)... –

+1

數據庫表.. – Aditii

回答

0

我有問題的略微不同的解釋:

SELECT DISTINCT t1.Unix, t2.Staffid 
FROM table1 t1, table2 t2 
WHERE t2.auth = 'Y' 
    AND t2.Staffid NOT IN (select Staffid FROM table1 WHERE Unix = t1.Unix) 
    ORDER BY t1.Unix; 
0
SELECT Staffid 
FROM table2 AS t2 
WHERE auth = 'y' 
    AND NOT EXISTS 
     (SELECT * 
     FROM table1 AS t1 
     WHERE t1.Staffid = t2.Staffid 
      AND t1.Unix = 232 
    )