I'm currently running a query like this:
SELECT *
FROM email
WHERE email_address LIKE 'ajones@%'
OR email_address LIKE 'bsmith@%'
OR email_address LIKE 'cjohnson@%'
The large number of OR's bothers me. Is there a way to condense this up with something akin to an IN operator, e.g.:
SELECT *
FROM email
WHERE email_address LIKE ('ajones@%', 'bsmith@%', 'cjohnson@%')
Or is this just wishful thinking?
解决方案
Here's what I recommend: Extract the part of the email address before the @ and use that before IN:
SELECT * FROM `email`
WHERE LEFT(`email_address`, LOCATE('@', `email_address`) - 1)
IN ('ajones', 'bsmith', 'cjohnson')