Chris Chris - 1 year ago 47
MySQL Question

Please check my mySQL query for phpMyAdmin

I am in need of changing multiple records in my database. I'm new to this so if someone would look at what I have figured out so far through my research and let me know if this looks correct I would appreciate it.

I have few thousand fields that contain "0" and I need to remove every "0" so it to contains nothing. So I ran a query to find them all.

FROM `wp_postmeta`
WHERE `meta_key` = '_regular_price'
AND `meta_value` = '0'

I now need every record or row of "meta_value" that contains "0" to be empty. After looking around I think I can run the following in my phpMyAdmin Query to remove "0" from every "meta_value" that contains "0" and leave all the others alone.

Does the following look correct?

UPDATE `wp_postmeta` SET `meta_value` = '' WHERE `meta_value` =0;

Thanks for your help.

Answer Source

Ok I just tried out the following

UPDATE `wp_postmeta` SET `meta_value` = '' WHERE `meta_key` = '_regular_price' AND `meta_value` = '0';

And it worked!

So using this I was able to update multiple rows of a table in one column to contain a blank value not a NULL value but a blank value. It updated 3562 records and left the other records alone.

Thanks for everyone's advice and tips and help they helped lead me in the right direction.