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 に答える