2011-02-24 44 views

回答

3

我假設你有一個表

user | friend 
------------- 
6 | 1 
6 | 2 
6 | 3 
6 | 4 
6 | 5 
7 | 1 
7 | 3 
7 | 5 

那麼你可以做

SELECT * 
FROM friends f1 
JOIN friends f2 USING (friend) 
WHERE f1.user = 6 
    AND f2.user = 7 

,你會得到

user | friend | user 
-------------------- 
6 | 1  | 7 
6 | 3  | 7 
6 | 5  | 7 
相關問題