Advertisement
Guest User

Untitled

a guest
Aug 12th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. -- create view
  2. create view all_border_pairs as
  3. select Country1, Country2 from borders
  4. union all
  5. select Country2, Country1 from borders;
  6.  
  7. -- query
  8. select distinct b1.Country1, b2.Country2
  9. from all_border_pairs b2
  10. join all_border_pairs b1 on b2.Country1 = b1.Country2
  11. where b2.Country2 <> b1.Country1
  12. and b1.Country1 = 'I' -- optionally filter for one country here
  13. and not b2.country2 in (select Country2 from all_border_pairs where Country1 = b1.Country1)
  14. order by b1.Country1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement