查询检查两个表中是否存在相同的值,如何组合这两个查询

时间:2016-04-01 12:36:28

标签: mysql

表1

SELECT COALESCE(EMAIL, FB_EMAIL)as EMAILId  FROM o2core.t_o2_user_profile_details  where USER_ID=10011;

查询1的输出是

    EMAILId
bhanupriya@gmail.com

表:2

SELECT CORP_USER_ID as  FROM o2core.t_o2_corp_user_reg_map as b where TH_ID=2 ;

查询2的输出是

    EMAILId
bhanupriya@gmail.com

1 个答案:

答案 0 :(得分:0)

尝试使用此查询:

SELECT COUNT(*) > 0 AS emailIsUsedTwice
FROM t_o2_user_profile_details AS p
INNER JOIN t_o2_corp_user_reg_map AS m ON m.CORP_USER_ID = COALESCE(p.EMAIL, p.FB_EMAIL)
WHERE p.USER_ID = 10011;

t_o2_corp_user_reg_map.CORP_USER_ID

上建立索引也很有用