Advertisement
Guest User

Untitled

a guest
May 12th, 2017
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Table 1 (records):
  2.  
  3. ORDER_NUMBER | Email Address
  4. -------------|--------------
  5. FX0422 | JUNK@what.com
  6. GF2304 | [null]
  7. 0Z3204 | [null]
  8. AS0234 | junk@improper.com
  9. AO3240 | [null]
  10.  
  11. table 2 (master list):
  12. ORDER_NUMBER | SSN
  13. -------------|-----
  14. FX0422 | 123456789
  15. GF2304 | 123451234
  16. 0Z3204 | 098765432
  17. AS0234 | 098760987
  18. A03240 | 456745678
  19.  
  20. table 3 (personnel list d):
  21. SSN | EMAIL_ADDRESS
  22. -------------|-----------------
  23. 123456789 | BOB@accounting.com
  24. 123451234 | jane@company.com
  25.  
  26. table 4 (personnel list l):
  27. SSN | EMAIL_ADDRESS
  28. ------------|----------------
  29. 098760987 | JOHN@company.com
  30. 456745678 | DILDO@company.com
  31. 098765432 | WOMBAT@company.com
  32.  
  33. Desired Output:
  34. ORDER NUMBER | EMAIL ADDRESS
  35. -------------|-----------------
  36. FX0422 | BOB@accounting.com
  37. GF2304 | jane@company.com
  38. 0Z3204 | WOMBAT@company.com
  39. AS0234 | JOHN@company.com
  40. AO3240 | DILDO@company.com
  41.  
  42.  
  43. select r.order_number, m.ssn
  44. from table1 r left outer join table2 m
  45. on m.ssn = (select SSN from table3
  46. UNION
  47. select SSN from table4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement