Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Update table wp_postmeta column meta_value where meta_key column equals certain value

I would like to update (divide the value by 100) in table wp_postmeta column meta_value where meta_key = price_cents

SQL TABLE
eg.

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE wp_postmeta SET meta_value = meta_value / 100 WHERE meta_key = price_cents;

Above SQL statemant gives me error:
#1054 - Unknown column 'price_cents' in 'where clause'

How to do it?

>Solution :

UPDATE wp_postmeta SET meta_value = meta_value / 100 WHERE meta_key = 'price_cents';

String literals belong in single-quotes.

The string ‘price_cents’ is stored as data, it’s not a column identifier. I can understand why this is a bit confusing, because the wp_postmeta table is a form of Entity-Attribute-Value table, which tries to model virtual attributes by adding rows of data. But when writing SQL, you must treat the data values as data values, even though they seem to name virtual attributes.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading