Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.