I have a database that I am trying to clean out. They have 70k entries with some bad values in the zip code column. I want to go through and delete the rows that do not have a valid 5 or 9 digit zip code. This the current statement I have:
SELECT * FROM `sample_requests` WHERE `request_zip` RegExp '^\d{5}$)|(^\d{5}-\d{4}$)'
I am not very familiar with regular expressions, but I know enough. Also this particular regex is used on the form now, so that it will not submit without a valid zip code so I know it works. I just can’t get the MySQL portion to work.
you need to use
DELETEinstead ofSELECT. Before you do this, you might want to create a duplicate ‘sample_requests’ table in case you make a mistake.here’s the command you’re interested in (deleting the duplicate table rows first so you know it works):