1

Table 1

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

output of query 1 is

    EMAILId
bhanupriya@gmail.com

Table:2

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

output of query 2 is

    EMAILId
bhanupriya@gmail.com
  • Possible duplicate of [What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?](http://stackoverflow.com/questions/5706437/whats-the-difference-between-inner-join-left-join-right-join-and-full-join) – dubes Apr 01 '16 at 13:13

1 Answers1

0

Try to use this query:

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;

It will be useful also to have an index on t_o2_corp_user_reg_map.CORP_USER_ID

Silvanu
  • 571
  • 3
  • 7