第 1 个表 - explore_offers:
- id
- Primary Key - offer_unique
第 2 表 - participated_explore_offers:
- id
- email - user_email
- Primary Key - offer_unique
我想要什么: * 显示第一个表记录,并排除那些在第二个表中找到特定电子邮件的记录
例如:
SELECT eo.*
, peo.user_email
FROM explore_offers eo
LEFT
JOIN participated_explore_offers peo
ON eo.offer_unique = peo.offer_unique
WHERE peo.user_email = 'test@gmail.com'
我试过那个例子,我得到了 0 条记录。 我在第一个表中有 2 条记录,在第二个表中有一条记录,我想要的结果是:
*。从第一个表中获取一条记录,而第二个表中不存在该记录。
第一个表格内容:
Nr id Primary Key
1 0 m1
2 1 m2
第二表内容
Nr id user_email Primary Key
1 0 test@gmail.com m1
1 0 test2@gmail.com m2
预期
Nr id Primary Key
1 1 m2
我有什么:
0 条记录
最佳答案
试试这个:
select * from explore_offers
where offer_unique not in
(select offer_unique from participated_explore_offers where user_email='test@gmail.com')
关于mysql - 当表2值不存在时,从表1中获取记录并从另一个表中加入它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47994084/