Guest User

Untitled

a guest
Oct 4th, 2018
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. ID email
  2. A a@gmail.com
  3.  
  4. ID email2 email3 email4
  5. A a@gmail.com null ab@gmail.com
  6.  
  7. select T1.ID, T1.email,
  8. case when T1.email<>T2.email2 then T2.email2 end email2,
  9. case when T1.email<>T2.email3 and T2.email2<>T2.email3 then T2.email3 end email3,
  10. case when T1.email<>T2.email4 and T2.email2<>T2.email4 and T2.email3<>T2.email4 then T2.email4 end email4
  11. from t1
  12. left join t2 on t1.id=t2.id
  13.  
  14. ID email email2 email3 email4
  15. A a@gmail.com null null null
  16.  
  17. ID email email2 email3 email4
  18. A a@gmail.com null null ab@gmail.com
  19.  
  20. select T1.ID, T1.email,
  21. case when T1.email<>T2.email2 then T2.email2 end email2,
  22. case when T1.email<>T2.email3 and T2.email2<>T2.email3 then T2.email3 end email3,
  23. case when (T1.email<>T2.email4 OR T1.email IS NULL) and
  24. (T2.email2<>T2.email4 OR T2.email2 IS NULL) and
  25. (T2.email3<>T2.email4 OR T2.email3 IS NULL) then T2.email4 end email4
  26. from t1
  27. left join t2 on t1.id=t2.id
Add Comment
Please, Sign In to add comment