I’d like to select people who live in california zipcodes. However this table i’m using stores zipcodes as string, instead of integers, so I havre to put a qutoe around it.
How can I select these values in range, instead of having to type it out?
I’d like to do something like this:
select people from tablename where postal_code >= '90001' and postal_code <= '96162'
Thank you!
Advertisement
Answer
While your query would probably work for this specific interval, you would be better off cast
ing the strings to integers to do proper numeric comparison:
select people from tablename where cast(postal_code as int) between 90001 and 96162
String and number comparison do not follow the same rules, and you would eventually get unexpected results by comparing strings. For example, string-wise, '9'
is greater than '10'
.