jaredsmith
jaredsmith

Reputation: 7563

MySQL Limiting Varchar Select

I'm not sure what command I am searching for so it was impossible for me to find it on Google since the closest thing I could find was limiting the amount of rows returned.

I have a table of zip codes and some are 5 characters (12345) and some are the longer 5 characters -dash- 4 characters (12345-1234). I want to select all zip codes so that the length is limited to 5 characters (they all look like 12345).

Thank you in advance.

Upvotes: 0

Views: 323

Answers (2)

peterm
peterm

Reputation: 92785

Use SUBSTR

SELECT SUBSTR(zip, 1, 5) AS zip FROM yourtable

Here is sqlfiddle

Upvotes: 1

Suhel Meman
Suhel Meman

Reputation: 3852

select SUBSTRING(zipcode,1,5) as zip_code from zipcode_table;

Upvotes: 1

Related Questions