1

我有 2 张桌子

用户表

id fname lname
1  asdf  fdg
2  asd2  ddf 
3  xsss  ss
4  frfr  dd 
5  dede  dd

并在用户关联表中

user1 associateduser
1      2
1      3

我想从不应包含 user1 及其关联用户的用户表中选择 id、fname、lname

4

2 回答 2

2

也许是这样的:

SELECT
    id,
    fname,
    lname
FROM
    user
WHERE NOT EXISTS
    (
        SELECT
            NULL
        FROM
            userassociation
        WHERE
            userassociation.user1=user.id
            AND userassociation.associateduser=user.id
    )
于 2012-05-07T12:00:10.773 回答
0
select id,fname,lname from `user`
where id not in (select user1 as u 
                 from userassociation 
                 union 
                 select associateduser as u 
                 from userassociation)
于 2012-05-07T12:00:08.050 回答