我有两张桌子
帐户 { acc_id,分数,... }
朋友 { acc_id,friend_id }
我需要查询来选择约翰的所有朋友的分数(例如)
就像是
SELECT (acc_id,score) FROM accounts WHERE (表友包含条目 (John,acc_id))
是否可以编写这样的查询?
谢谢
我有两张桌子
帐户 { acc_id,分数,... }
朋友 { acc_id,friend_id }
我需要查询来选择约翰的所有朋友的分数(例如)
就像是
SELECT (acc_id,score) FROM accounts WHERE (表友包含条目 (John,acc_id))
是否可以编写这样的查询?
谢谢
Yes, you will need to use a subquery. It should look something like this:
Select acc_id, score from accounts
where acc_id in (select acc_id where friend_id = 'John'sID');
使用子查询:
Select acc_id, score from accounts
where acc_id in (select acc_id from friends where friend_id = 'John'sID');
或使用加入:
Select accounts.acc_id, score from accounts
Left Join friends using (acc_id)
where friend_id = 'John'sID';