2013-07-23 71 views
0

我有兩個表與條件的另一個查詢

複雜的查詢

帳戶{ACC_ID,得分,...}

朋友{ACC_ID,friend_id}

我需要查詢選擇的分數約翰(例如)

喜歡的東西

的所有朋友

SELECT(ACC_ID,分數)FROM WHERE(表的朋友含有條目(約翰,ACC_ID))賬戶

是否可以寫這樣的查詢?

謝謝

回答

0

是的,您將需要使用子查詢。它應該是這個樣子:

Select acc_id, score from accounts 
    where acc_id in (select acc_id where friend_id = 'John'sID'); 
0

使用子查詢:

Select acc_id, score from accounts 
where acc_id in (select acc_id from friends where friend_id = 'John'sID'); 

OR 使用加入:

Select accounts.acc_id, score from accounts 
Left Join friends using (acc_id) 
where friend_id = 'John'sID';