我正在尝试从表 A 中选择当前用户在表 B 中不存在的所有记录。
事实上,我有一个项目,从表 A 获取横幅并向用户显示,然后我将此事件插入表 B(参见日志),但我不喜欢向用户显示重复的横幅。
表 A(横幅):
+-----------+
| bannerKey |
+-----------+
| x7y3 |
| r2s4 |
| j6n2 |
+-----------+
表 B(参见日志):
+-----------++----------+
| bannerKey || userName |
+-----------++----------+
| x7y3 || jack |
| j6n2 || Chris |
| r2s4 || Nicola |
| j6n2 || Allen |
| j6n2 || Nicola |
+-----------++----------+
那么,我如何从表 A 中获取当前用户的记录,该记录当前用户过去没有看到此帖子?
最佳答案
试试这个:
select *
from banners a
where not exists (
select 1
from table2 b
where username = 'currentusername' -- substitute username here
and a.bannerKey = b.bannerKey
)
关于php - 从当前用户的表 B 中选择不存在的表 A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42043110/