Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID email
- A a@gmail.com
- ID email2 email3 email4
- A a@gmail.com null ab@gmail.com
- select T1.ID, T1.email,
- case when T1.email<>T2.email2 then T2.email2 end email2,
- case when T1.email<>T2.email3 and T2.email2<>T2.email3 then T2.email3 end email3,
- case when T1.email<>T2.email4 and T2.email2<>T2.email4 and T2.email3<>T2.email4 then T2.email4 end email4
- from t1
- left join t2 on t1.id=t2.id
- ID email email2 email3 email4
- A a@gmail.com null null null
- ID email email2 email3 email4
- A a@gmail.com null null ab@gmail.com
- select T1.ID, T1.email,
- case when T1.email<>T2.email2 then T2.email2 end email2,
- case when T1.email<>T2.email3 and T2.email2<>T2.email3 then T2.email3 end email3,
- case when (T1.email<>T2.email4 OR T1.email IS NULL) and
- (T2.email2<>T2.email4 OR T2.email2 IS NULL) and
- (T2.email3<>T2.email4 OR T2.email3 IS NULL) then T2.email4 end email4
- from t1
- left join t2 on t1.id=t2.id
Add Comment
Please, Sign In to add comment