Jump to content

[SOLVED] SQL Command to remove last five characters from table record


TecTao

Recommended Posts

I'm sorry, I posted a help earlier and didn't make it clear that what I was looking for was a sql command to remove certain part from a 24,000 row table.

 

I have a column of zip codes in an table called zips.  They are the 9 number rather then simple 5 number such as 12345-6789 in each record, approximately 24,000 records.

 

I am looking for a mysql command to strip/remove/remove and truncate the last five characters from each record, in the example above, the -6789, leaving only the 5 digit zip code.

 

I would do this in a sql command in phpMyAdmin for this particular table.

 

Any help is appreciated, and thankyou in advance.

mike

Thanks, and that will work if I'm returning a sql query I believe.

 

What I am looking for is a sql command to delete the last 5 characters from every record in the zip column of the contacts table.

 

My plan is to run the command in the sql query window of myPHPAdmin for the contacts table and edit every record in the zip column

Always make a backup before trying anything.

 

UPDATE table_name SET field = LEFT(field, CHAR_LENGTH(field)-5);

 

I usually run the equivalent select side-by-side with the original column to double-check before backing up and updating.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.