• Resolved doghi

    (@doghi)


    Hello there,

    I want to make an php query and update statement to keep connected some databases from different platforms.

    The only thing in common in my databases are the SKU and i need to update stocks using only SKU.

    Until now i manage to update my produc stocks using meta_id but now i need to change it SKU update.

    My model of update using meta_id
    UPDATE wp3l_postmeta SET meta_value = ’51’ WHERE wp3l_postmeta.meta_key = ‘_stock’ AND wp3l_postmeta.meta_id = “24886”

    i need to remove that meta_id and replace it with SKU = “model1” for example.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    meta_id is a column in the postmeta table, there is not any “SKU” column (at least there shouldn’t be), such that you cannot directly replace meta_id with SKU. I think the WHERE clause syntax you are looking for is closer to
    wp3l_postmeta.meta_key = 'SKU' AND wp3l_postmeta.meta_value = '123456';

    Thread Starter doghi

    (@doghi)

    Here i have an image with a product.

    I have meta key _sku with my product sku and meta key for stock _stock.

    I want to update the stock using sku.

    Moderator bcworkz

    (@bcworkz)

    We need the post ID from the SKU record in order to update the correct stock record. Thus we need to query the SKU record as a subquery. That’s a little beyond my limited MySQL skills, but I think something like this:
    UPDATE wp3l_postmeta SET meta_value = 'stock-value' WHERE wp3l_postmeta.meta_key = '_stock' AND wp3l_postmeta.post_id = (SELECT post_id FROM wp3l_postmeta WHERE wp3l_postmeta.meta_key = '_sku' AND wp3l_postmeta.meta_value = 'sku-value');

    Thread Starter doghi

    (@doghi)

    Yeap, i think this is the right way. Thx for you help, i will do some test then i will close my post.

    Thread Starter doghi

    (@doghi)

    Thx for help, its ok this code.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Update stock from sql (phpmyadmin) by product SKU’ is closed to new replies.