基于电子邮件列表sql查询表的最佳方法

时间:2014-08-20 02:06:15

标签: mysql sql list search

我有一份电子邮件列表,我需要提取哪些记录。我确定我这样做的方式不对:

SELECT * FROM `MY_TABLE` 
WHERE 
field_1 = 'something'
AND
created BETWEEN '2014-06-01 00:00:00' AND '2014-06-30 23:59:59'
AND 
   email ="emaillist1@email.com"
OR email ="emaillist2@email.com"
OR email ="emaillist3@email.com"

这会返回所有带有帐户的电子邮件但忽略了field_1,因此它们都不同。 有没有更好的办法?电子邮件列表超过100个。感谢。

2 个答案:

答案 0 :(得分:3)

您应该使用in

SELECT *
FROM `MY_TABLE` 
WHERE field_1 = 'something' AND
      created BETWEEN '2014-06-01 00:00:00' AND '2014-06-30 23:59:59' AND 
      email IN ('emaillist1@email.com', 'emaillist2@email.com', 'emaillist3@email.com');

您应该对字符串和日期常量使用单引号。

答案 1 :(得分:1)

使用括号并尝试

 SELECT * FROM `MY_TABLE` 
    WHERE 
    field_1 = 'something'
    AND
    created BETWEEN '2014-06-01 00:00:00' AND '2014-06-30 23:59:59'
    AND 
       (email ="emaillist1@email.com"
    OR email ="emaillist2@email.com"
    OR email ="emaillist3@email.com")