mysql 使用多个表格搜索电子邮件和域名
mysql Search an email and domain name with multiple tables
我有 3 mysql 个表:
unsubscribers
=> (id, email)
bounces
=> (id, email, bounce_reason)
blacklists
=> (id, domain)
假设我们必须搜索电子邮件 ID:something@someone.com
和域:someone.com
(即电子邮件 ID)
我想编写这样一个查询,它将搜索存在于 unsubscribers
或 bounces
中的 Email ID
,或存在于 blacklists
中的 domain
所以就像,如果这些表中存在电子邮件 ID 或域,我应该得到结果 1 或 0。如果这不可能,至少我应该得到数据
在此先感谢您的帮助
我找到了解决方法。下面的查询完成了所有工作
SELECT (SELECT count(`email`) FROM `unsubscribers` WHERE `email` = 'rsakhale@gmail.com') AS `unsubscribers`,
(SELECT count(`email`) FROM `bounces` WHERE `email` = 'rsakhale@gmail.com') AS `bounces`,
(SELECT count(`name`) FROM `blacklists` WHERE `name` = 'gmail.com') AS `blacklists`
它returns
+---------------+---------+------------+
| unsubscribers | bounces | blacklists |
+---------------+---------+------------+
| 1 | 0 | 0 |
+---------------+---------+------------+
啊,这是一个菜鸟问题:'(
我有 3 mysql 个表:
unsubscribers
=> (id, email)
bounces
=> (id, email, bounce_reason)
blacklists
=> (id, domain)
假设我们必须搜索电子邮件 ID:something@someone.com
和域:someone.com
(即电子邮件 ID)
我想编写这样一个查询,它将搜索存在于 unsubscribers
或 bounces
中的 Email ID
,或存在于 blacklists
中的 domain
所以就像,如果这些表中存在电子邮件 ID 或域,我应该得到结果 1 或 0。如果这不可能,至少我应该得到数据
在此先感谢您的帮助
我找到了解决方法。下面的查询完成了所有工作
SELECT (SELECT count(`email`) FROM `unsubscribers` WHERE `email` = 'rsakhale@gmail.com') AS `unsubscribers`,
(SELECT count(`email`) FROM `bounces` WHERE `email` = 'rsakhale@gmail.com') AS `bounces`,
(SELECT count(`name`) FROM `blacklists` WHERE `name` = 'gmail.com') AS `blacklists`
它returns
+---------------+---------+------------+
| unsubscribers | bounces | blacklists |
+---------------+---------+------------+
| 1 | 0 | 0 |
+---------------+---------+------------+
啊,这是一个菜鸟问题:'(