0

I want to get query for all UK members of global database.

I can use Ansi SQL and have regular expression support.

It's not mine to modify so I can't create tables in it and it's too big to geocode

 SELECT 
   login,
   location
 FROM GLOBALDATA
 where 
 (
  lower( location) like '%united kingdom%' or
  (lower( location) like '%england%' 
    and lower( location) not like '%new england%'
  ) 
  or
  (lower( location) like '%london%' 
    and lower( location) not like 'london%on' 
    and lower( location) not like '%ontario%'
    and lower( location) not like '%canada%'
  )
  or
  (lower( location) like '%uk%' 
    and lower( location) not like '%breukelen%'
    and lower( location) not like '%takatsuki%'
    and lower( location) not like '%phuket%'
    and lower( location) not like '%fukushima%'
    and lower( location) not like '%ukarine%'
    and lower( location) not like '%ukrain%'
    ...
    and lower( location) not like '%ortenaukreis%'
    and lower( location) not like '%takarazuka%'
    and lower( location) not like '%mukwonago%'
    and lower( location) not like '%ukrane%'
    and lower( location) not like '%sukabumi%'
    and lower( location) not like '%milwaukee%'
  )
  or
  lower( location) like '%sussex%'
  or
  (lower( location) like '%bristol%'
  -- ignore bristol, VA
  and lower( location) not like '%va%'
  )

  -- uk towns
  --
  -- http://www.dangibbs.co.uk/journal/free-uk-postcode-towns-counties-database
  --
  or lower( location) like 'abbots langley%'
  or lower( location) like 'abbotsham%'
  or lower( location) like 'abenbury%'
  or lower( location) like 'aberaeron%'
  or lower( location) like 'abercarn%'
  ....
  or lower( location) like 'yealmpton%'
  or lower( location) like 'yeovil%'
  or lower( location) like 'ystrad%'
  or lower( location) like 'ystradgynlais%'
)
-- AND we DONT want
-- http://statetable.com/
--
and not 
-- state codes
(
   location like '%, AA'
  or  location  like '%, AE'
  or  location  like '%, AP'
  ...
  or  location  like '%, VT'
  or  location  like '%, WA'
  or  location  like '%, WI'
  or  location  like '%, WV'
  or  location  like '%, WY'

  -- also state names
  or  location like '%Alabama'
  or  location like '%Alaska'
  or  location like '%Arizona'
  ...
  or  location like '%Kingman Reef'
  or  location like '%Navassa Island'
  or  location like '%Serranilla Bank'
  or  location like '%Bajo Nuevo Bank'
)

My question is does anyone know if anyone has something more general purpose than this for other countries?

I cant find anything..

HaveAGuess
  • 1,231
  • 1
  • 13
  • 23
  • 2
    What DBMS are you using and why are you grouping by login? – Dave Jemison Jun 19 '14 at 21:08
  • What does the data look like? It seems really strange to me to have a field that might contain both "Milwaukee" and "Great Britain". – Gordon Linoff Jun 19 '14 at 21:34
  • So I'll remove the group by as that's irrelevant. US has many cities with similar names to UK, so ignoring US states help eliminate similar names there – HaveAGuess Jun 20 '14 at 00:02

0 Answers0