[英]MySQL select data across 4 tables (multiple conditions)
感謝另一個用戶,我終於能夠使用此查詢收集一些數據:
SELECT r.form, s.value as email
FROM subrecords s join
records r
on s.record = r.id AND r.name = 'question-form'
WHERE s.title = 'email'
GROUP BY s.value, r.form
有關上述查詢所涉及表的詳細信息,請參見在多個表中查找數據的MYSQL表中的重復項(需要多個條件)
通過上面的查詢,我獲得了提交特定表單的電子郵件列表。
現在,我需要使用上面列出郵件地址的查詢的“ s.value”來找出那些郵件地址中的哪個已訂閱特定的郵件列表
我首先需要找出識別每個唯一訂戶及其電子郵件地址的subscriber.subid,在該處我將加入上面查詢的結果
表->訂戶模式
subid | 電子郵件
然后從下表中選擇WHERE listid ='33'
表-> listsub模式
listid | subid | 子日期| 取消訂閱| 狀態
非常感謝每個人提供的不可思議的幫助!
這是通過執行更多聯接的方法:
SELECT r.form, s.value as email,
(case when max(l.listid is not null) then 'YES' else 'NO' end) as InList33
FROM subrecords s join
records r
on s.record = r.id AND r.name = 'question-form' left outer join
subscriber_schema ss
on ss.email = s.value left outer join
listsub l
on ss.subid = l.subid and
l.listid = '33'
WHERE s.title = 'email'
GROUP BY s.value, r.form;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.