Table 1 – USERS:
user_id | email_id | type
---------------------------------------
000121 | test_20@test.com | EXT
000125 | best_21@test.com | LOT
000128 | lite_21@test.com | EXT
Table 2- HISTORY:
old_user_id | new_user_id | another_type
----------------------------------------
000128 | 000121 | INIT
I have email_id in hand say test_20@test.com, I want to do a join query that should return 1, if the user_email_id I had, is in USERS table with EXT as TYPE and in HISTORY table with ANOTHER_TYPE as INIT;
I have a query with a single join for old_user_id .
IF EXISTS (SELECT 1 FROM history cmr (nolock)
INNER JOIN users au (nolock)
ON au.user_id = cmr.old_user_id
AND cmr.another_type = 'INIT 'AND au.type = 'EXT'
AND au.email_id = 'test_20@test.com')
SELECT 1 ELSE SELECT 0
When I query test_20@test.com or test_20@test.com, it should return 1. I want to add the join condition for new_user_id also .
So either user (old or new) should be EXT in USERS, and should be INIT in HISTORY
Thanks in advance
1 Answer