简体   繁体   English

MySQL在4个表中选择数据(多种条件)

[英]MySQL select data across 4 tables (multiple conditions)

Thanks to another user I was finally able to collect some data using this query: 感谢另一个用户,我终于能够使用此查询收集一些数据:

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

details on the tables involved in the above query are found at Finding duplicates in MYSQL table where data is in multiple tables (multiple conditions needed) 有关上述查询所涉及表的详细信息,请参见在多个表查找数据的MYSQL表中的重复项(需要多个条件)

With the above query I get the list of emails that submitted a specific form. 通过上面的查询,我获得了提交特定表单的电子邮件列表。

I would need now to find out which of those email addresses is subscribed to a specific mailing list, Using the "s.value" of the above query which lists email addresses 现在,我需要使用上面列出邮件地址的查询的“ s.value”来找出那些邮件地址中的哪个已订阅特定的邮件列表

I first need to find out the subscriber.subid which identifies each unique subscriber and their email address, which is where I would join the result from the query above 我首先需要找出识别每个唯一订户及其电子邮件地址的subscriber.subid,在该处我将加入上面查询的结果

table -> subscriber schema 表->订户模式

subid | subid | email 电子邮件

Then select from the following table WHERE listid = '33' 然后从下表中选择WHERE listid ='33'

table -> listsub schema 表-> listsub模式

listid | listid | subid | subid | subdate | 子日期| unsubdate | 取消订阅| status 状态

Thank you so much everyone for the incredible help! 非常感谢每个人提供的不可思议的帮助!

Here is a way by doing more joins: 这是通过执行更多联接的方法:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM