本文介绍了mySQL - 减去另一个表中存在的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果这是重复的,我很抱歉,但是,我找不到我需要的答案.
I apologize if this is a duplicate, however, I cannot find the answer I need.
考虑我的数据:
表格 - report_detail
report_id |category |sub_category |report name
-------------------------------------------------------
1 |1 |1 |Donkey Report
2 |2 |2 |Grandma Report
3 |1 |1 |Poop Report
表格 - report_subscriptions
user_id |report_id
--------------------------
1 |1
2 |2
1 |2
我的问题是,如何从 report_detail 表中选择所有未订阅 report_subscriptions 中的 user_id = 1 的 report_id?
My question is, how do I select all of the report_id's from the report_detail table that are not subscribed to user_id = 1 in report_subscriptions?
谢谢!
推荐答案
这应该会让你相当接近
select * from Report_detail RD
where RD.report_id not in (select disctinct RS.report_id from report_subscriptions RS)
这篇关于mySQL - 减去另一个表中存在的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!