2017-02-04 7 views
0

現在のユーザのテーブルBには存在しないテーブルAのすべてのレコードを選択しようとしています。
実際には、テーブルAからバナーを取得してユーザーに表示するプロジェクトがあります。次に、このアクティビティをテーブルBに挿入します(ログを参照してください)。

表A(バナー):現在のユーザのテーブルBに存在しないテーブルAから選択

+-----------+ 
| bannerKey | 
+-----------+ 
| x7y3  | 
| r2s4  | 
| j6n2  | 
+-----------+ 

表B(ログを参照):

+-----------++----------+ 
| bannerKey || userName | 
+-----------++----------+ 
| x7y3  || jack  | 
| j6n2  || Chris | 
| r2s4  || Nicola | 
| j6n2  || Allen | 
| j6n2  || Nicola | 
+-----------++----------+ 

だから、どのように私は、現在のユーザーのためのテーブルAからレコードを取得することができ、現在のユーザー、ドンという過去にこの投稿が表示されていませんか?

答えて

0

これを試してみてください:

select * 
from banners a 
where not exists (
    select 1 
    from table2 b 
    where username = 'currentusername' -- substitute username here 
    and a.bannerKey = b.bannerKey 
) 
+0

それがうまく働いています!大変ありがとう! –

0

あなたは

select * 
from table_a 
were bannerKey not in (select 
         bannerKey from table_b) 

ではありませんを使用することができたり参加

select * 
from table_b 
left join table_b a.bannerKey = b.bannerKey 
where a.bannerKey is null 
関連する問題