TecTao Posted June 21, 2007 Share Posted June 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/ Share on other sites More sharing options...
Wildbug Posted June 21, 2007 Share Posted June 21, 2007 LEFT(zip_col,5) Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/#findComment-279524 Share on other sites More sharing options...
TecTao Posted June 21, 2007 Author Share Posted June 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/#findComment-279534 Share on other sites More sharing options...
effigy Posted June 21, 2007 Share Posted June 21, 2007 Always make a backup before trying anything. UPDATE table_name SET field = LEFT(field, CHAR_LENGTH(field)-5); Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/#findComment-279562 Share on other sites More sharing options...
TecTao Posted June 21, 2007 Author Share Posted June 21, 2007 Thanks, that's perfect Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/#findComment-279576 Share on other sites More sharing options...
fenway Posted June 27, 2007 Share Posted June 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/56604-solved-sql-command-to-remove-last-five-characters-from-table-record/#findComment-284290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.