2 Replies - 686 Views - Last Post: 14 March 2010 - 11:03 PM Rate Topic: -----

#1 eddywebs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-April 09

Need help in creating this SQL query

Posted 14 March 2010 - 08:27 PM

Hi , I am trying to come up with a SQL query to update a custom field value of all the wordpress posts at once.

The custom field is "price" : and I am trying to update all the values by 20% (that is .20*price) .

I know all the custom fields are stored at wp_postmeta table

The field name which in this case is "price" is stored at the meta_key column
The value if the "price" is stored under meta_value column

so what I am trying to do is increase the value each row of meta_value column where the meta_key has the value price

I am attaching an screenshot for better explanation :P

Posted Image

Attached image(s)

  • Attached Image

This post has been edited by eddywebs: 14 March 2010 - 09:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help in creating this SQL query

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: Need help in creating this SQL query

Posted 14 March 2010 - 09:50 PM

So just to make sure we are clear, you want to adjust each price value to 20% of its value on each row where the meta_key value is "price" right?

If this is correct then you should be able to do this...

Update wp_postmeta set meta_value = (meta_value * .20) where meta_key = 'price';



Edit: This makes the new value 20% of the original price. If you wanted to increase the price by 20% that would be times 1.20

This query is saying for every row where meta_key is equal to the word "price" update its meta_value to meta_value times .20 (that is, make price 20% of its original value... aka if it was 100 dollars it would now be 20 dollars). Let us know if this is not what you are looking to do.

:)

This post has been edited by Martyr2: 14 March 2010 - 09:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 eddywebs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-April 09

Re: Need help in creating this SQL query

Posted 14 March 2010 - 11:03 PM

got it ! :rolleyes: your query worked like a charm !!

Thanks @Martyr2 , I really appreciate your efforts .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1