0

I'm trying to Select all records from table A which does not exist in table B for Current user.
In fact, I have a project that get banner from table A and show to user, Then i insert this activity to table B (see log) That I whould not like show a Repetitious banner to a user.

Table A (banners):

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

Table B (see log):

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

So, How can i get a record from table A for current user that The current user, don't see this post in past?

Amir m
  • 13
  • 6

2 Answers2

0

You could use a not in

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

or a join

select * 
from table_b
left join table_b a.bannerKey  = b.bannerKey
where a.bannerKey is null   
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

Try this:

select *
from banners a
where not exists (
    select 1
    from table2 b
    where username = 'currentusername'  -- substitute username here
    and a.bannerKey = b.bannerKey
)
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76