需要在两个表上编写查询

时间:2013-01-08 08:04:22

标签: mysql

我有两张桌子

Member (member_id,...)
friend-requests(member_id, friend_id)

我需要从member成员表中获取所有记录,其中member_id为19,哪些不在列friend_id

2 个答案:

答案 0 :(得分:1)

select * from member join friend-requests
on member.member_id=friend_requests.member_id
where
member.member_id=19
and
not exists (select f.member_id from friend-requests f where f.mmeber_id = member.member_id)

答案 1 :(得分:0)

Select m.* from Member as m 
where member_id=19 and 
member_id not in (select friend_id from friend_requests where member_id=19)