I have the following query that works fast:
SELECT CUSTOMER FROM (
SELECT CUSTOMER FROM
EMAILS INNER JOIN CUSTOMERS
ON EMAILS.email=CUSTOMERS.email1
UNION
SELECT CUSTOMER FROM
EMAILS INNER JOIN CUSTOMERS
ON EMAILS.email=CUSTOMERS.email2)
But cross join is taking forewer:
SELECT DISTINCT CUSTOMER FROM
EMAILS INNER JOIN CUSTOMERS
ON EMAILS.email=CUSTOMERS.email1
OR EMAILS.email=CUSTOMERS.email2
-- alternative: EMAILS.email in (CUSTOMERS.email1,CUSTOMERS.email2)