1

私は以下のクエリをどのように書くかについて少し混乱しています:

私は2つのテーブルを持っています

tbl_one
ID      TEXT
1       test1
2       test2
3       test3
4       test4
5       test5

tbl_two
ID      userID      tblone_ID
1       50          1
2       100         1
3       100         2

tbl_twoには表示されないが、特定のユーザー用のtbl_oneの行を取得しようとしています。

たとえば、以下を選択します。

select * from tbl_one, tbl_two 
where (tbl_two.tblone_ID !=tbl_one.ID and tbl_two.userID==50) 

私の欲望の復活は

Desire resalt:
ID      TEXT
2       test2
3       test3
4       test4
5       test5
4

5 に答える 5

2
SELECT  a.*
FROM    tableA a
        LEFT JOIN tableB b
          on a.ID = b.tblone_ID AND
              b.userID = 50
WHERE   b.tblone_ID IS NULL
于 2012-11-02T09:49:08.863 に答える
1
select * 
from tbl_one 
where ID not in (select tblone_ID 
                 from tbl_two 
                 where userID = 50) 
于 2012-11-02T09:43:36.900 に答える
1
select * from tbl_one where tbl_one.ID not in ( Select tblone_ID
FRom tbl_two where userID=50)

SELECT * from tbl_one inner Join tbl_two on tbl_one.ID !=tblone_ID  where userID=50
于 2012-11-02T12:49:33.803 に答える
0
SELECT * FROM tbl_one
LEFT JOIN tbl_two on tbl_one.ID = tbl_two.tblone_ID
WHERE tbl_one.ID IS NULL AND tbl_two.userID = 50
于 2012-11-02T09:44:55.897 に答える
0

あなたはこれを試すことができます

select * from tbl_one t1 
where t1.id not in (select tblone_id from tbl_two where tbl_two.userid=50)
于 2012-11-02T09:45:31.743 に答える