我有一个查询,其中包含订阅了30天的简报试用版的电子邮件列表..
$thirty = time() - 3024000;
SELECT c.email
FROM tbl_clients AS c
JOIN tbl_clientoptions AS o ON o.client = c.id
WHERE o.option = 'newsletter'
AND c.datecreated > $thirty
我想要做的是检查同一个查询,这样如果客户端有tbl_clientoptions.option ='trialoverride',它还会返回超过30天的客户端(即客户机选项表中的一行,其值为“ trialoverride“)
TBL_CLIENTS
表:
TBL_CLIENTOPTIONS
表:
答案 0 :(得分:0)
怎么样:
SELECT c.email
FROM tbl_clients AS c JOIN tbl_clientoptions AS o
ON o.client = c.id
WHERE (o.option = 'newsletter' AND c.datecreated > $thirty)
|| o.option = 'trialoverride';
答案 1 :(得分:0)
通常只有一个OR
条件会执行此操作,如果同一用户用户同时具有这两个条件,则添加DISTINCT
,否则将其删除:
SELECT DISTINCT c.email
FROM tbl_clients c
INNER JOIN tbl_clientoptions o ON (o.client = c.id)
WHERE
(o.option = 'newsletter' AND c.datecreated < $thirty) OR
(o.option = 'trial override' AND c.datecreated > $thirty);