我有以下快速运行的查询:
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)
但是交叉加入正在取决于:
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)
答案 0 :(得分:0)
关于OR
与Union
的讨论已经有很多,你可以在这里查看
由于您要将一列与两个不同的列进行比较,您也可以尝试使用
SELECT DISTINCT CUSTOMER
FROM EMAILS
INNER JOIN CUSTOMERS
ON EMAILS.email in (CUSTOMERS.email1,CUSTOMERS.email2)
此外,您在第一次查询时不需要DISTINCT
Union
会删除重复项