Reputation: 4437
I have a list of emails who's records I need to pull. I'm sure I'm doing this the wrong way:
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 ="[email protected]"
OR email ="[email protected]"
OR email ="[email protected]"
this returned all the emails with the accounts but ignored field_1, so they were all different. Is there a better way? The list of emails is over 100 long. Thanks.
Upvotes: 1
Views: 2561
Reputation: 1269873
You should use 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 ('[email protected]', '[email protected]', '[email protected]');
You should use single quotes for string and date constants.
Upvotes: 4
Reputation: 2006
Use bracket and try
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 ="[email protected]"
OR email ="[email protected]"
OR email ="[email protected]")
Upvotes: 1