Guest User

Untitled

a guest
May 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. -- Your code
  2. create table fg_180512_interactors_matches_party distkey(matched_id) sortkey(matched_id) as
  3. select
  4. democrats.fg_180512_interactors_matches_2.matched_id, -- Use an alias, a in this instance.
  5. source_id,
  6. score,
  7. LEFT(b.vb_vf_voter_status,1) as vb_vf_voter_status,
  8. LEFT(b.vb_vf_party,1) as vb_vf_party,
  9. ROUND(b.ts_tsmart_partisan_score) as ts_tsmart_partisan_score
  10. from democrats.fg_180512_interactors_matches_2 a
  11. left join ts.ntl_current as b using (matched_id) -- Matched id doesn't exist in ts.ntl_current, so you can't join on this column.
  12. -- See below for example of a.key = b.key
  13.  
  14. -- Working code...
  15. create table fg_180512_interactors_matches_party distkey(matched_id) sortkey(matched_id) as
  16. select
  17. matched_id, --removed schema designation
  18. source_id,
  19. score,
  20. LEFT(b.vb_vf_voter_status,1) as vb_vf_voter_status,
  21. LEFT(b.vb_vf_party,1) as vb_vf_party,
  22. ROUND(b.ts_tsmart_partisan_score) as ts_tsmart_partisan_score
  23. from democrats.fg_180512_interactors_matches_2 as a -- Added an alias, use this instead of a full table/schema name.
  24. left join ts.ntl_current as b on a.matched_id=b.vb_voterbase_id
  25.  
  26. -- Aliases, here is a basic example.
  27. select
  28. a.primary_key -- You are grabbing the column from table1
  29. b.first_name -- You aer grabbing the column from table2
  30. from schema.table1 as a
  31. left join schema.table2 b on a.primary_key = b.primary_key
Add Comment
Please, Sign In to add comment