h*******3 发帖数: 52 | 1 两个表,
users: userid, username, zipcode
friends: userid, friendid (also an userid), friendname
找出一个 user 的所有在某个 zipcode 的 friends id.
我想出来的答案:
select userid, zipcode from users A where A.userid in (select friendid from
friends B where B.userid = "****") and A.zipcode = "***";
大家觉得这个答案如何? | V****r 发帖数: 925 | 2 Select distinct(friendid)
from users u
join friends f on u.userid = f.userid
where u.userid = xxxxxxx
and u.zipcode = xxxxxxx
话说TABLE users 的primary key是userid吧? 那么zipcode可以不用管:
Select distinct(friendid)
from users u
join friends f on u.userid = f.userid
where u.userid = xxxxxxx |
|