mysql使用多个表搜索电子邮件和域名

时间:2015-04-30 11:25:58

标签: php mysql search join multiple-tables

我有3个mysql表:

unsubscribers => (id, email)

bounces => (id, email, bounce_reason)

blacklists => (id, domain)

假设我们必须搜索电子邮件ID:something@someone.com和域名:someone.com(即电子邮件ID)

我想写一个搜索Email IDunsubscribers中存在的bouncesdomain中存在的blacklists

所以,如果这些表中存在电子邮件ID或域,我应该得到1或0的结果。如果这不可能,至少我应该得到数据

提前感谢您的帮助

1 个答案:

答案 0 :(得分: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`

它返回

+---------------+---------+------------+
| unsubscribers | bounces | blacklists |
+---------------+---------+------------+
|             1 |       0 |          0 |
+---------------+---------+------------+

啊,这是一个菜鸟问题:'(