Skip to content

Instantly share code, notes, and snippets.

@sjtalkar
Last active October 9, 2020 15:22
Show Gist options
  • Save sjtalkar/f4634f4e54c70c60b35ecf794b18b91f to your computer and use it in GitHub Desktop.
Save sjtalkar/f4634f4e54c70c60b35ecf794b18b91f to your computer and use it in GitHub Desktop.
SQL for partial string comparison
--Option 1
select metropolitanarea,
nhl_team,
team,
win,
loss
from cities_expanded c,
nhl_data n
where n.team like '%' || nhl_team || '%';
--Option 2
select metropolitanarea,
nhl_team,
team,
win,
loss
from cities_expanded c, nhl_data n
where n.team ~ nhl_team ;
--Option 3
select metropolitanarea,
nhl_team,
team,
win,
loss
from cities_expanded c, nhl_data n
where position(c.nhl_team in n.team ) > 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment