Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- create view
- create view all_border_pairs as
- select Country1, Country2 from borders
- union all
- select Country2, Country1 from borders;
- -- query
- select distinct b1.Country1, b2.Country2
- from all_border_pairs b2
- join all_border_pairs b1 on b2.Country1 = b1.Country2
- where b2.Country2 <> b1.Country1
- and b1.Country1 = 'I' -- optionally filter for one country here
- and not b2.country2 in (select Country2 from all_border_pairs where Country1 = b1.Country1)
- order by b1.Country1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement