Results 1 to 10 of 18

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Amsterdam, The Netherlands
    Posts
    21
    Plugin Contributions
    0

    Default Problems with query change price in 2 tables

    I have a problem to change prices from 1 table to another table.

    table 1
    inventory
    -itemnumber
    -price

    table 2
    zen_products
    -products_model
    -products_price

    in table 1 (inventory) are the right prices

    it's has to compare the itemnumber with the products_model when it is the same, change the price from table zen_products with the price from tabel inventory.

    I have try this for someny hours, but everytime with this query below the prices from table 2 = zero

    below the query i use.

    I hope somebody can help me with that.

    Thanks.

    UPDATE zen_products
    SET products_price = ( SELECT inventory.Price
    FROM inventory
    WHERE inventory.itemNumber = zen_products.products_model)
    WHERE EXISTS
    ( SELECT inventory.Price
    FROM inventory
    WHERE inventory.itemNumber = zen_products.products_model);

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Problems with query change price in 2 tables

    Why not make it a lot simpler, like this:
    Code:
    update zen_products p, inventory i
    set p.products_price = i.Price
    where p.products_model = i.itemNumber;
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Dec 2008
    Location
    Amsterdam, The Netherlands
    Posts
    21
    Plugin Contributions
    0

    Default Re: Problems with query change price in 2 tables

    Thank you Dr. Byte for your fast reply

    I don't know what is p and i?

  4. #4
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Problems with query change price in 2 tables

    Those are aliases which make it possible to avoid using tablenames repeatedly. p refers to zen_products and i refers to inventory
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Dec 2008
    Location
    Amsterdam, The Netherlands
    Posts
    21
    Plugin Contributions
    0

    Default Re: Problems with query change price in 2 tables

    ok so i can copy exactly your query into my database
    and that will be the solution?

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Problems with query change price in 2 tables

    I hope so :)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Change Display price with attribute LARGEST price not lowest
    By bubbadan in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 7 Feb 2020, 05:37 AM
  2. v154 Help with a SQL Query for Query Builder
    By lindasdd in forum Managing Customers and Orders
    Replies: 2
    Last Post: 24 Mar 2016, 01:18 PM
  3. Replies: 0
    Last Post: 7 Dec 2009, 06:59 PM
  4. Problems with J-Query Template
    By Adrian88 in forum Addon Templates
    Replies: 10
    Last Post: 24 Nov 2008, 09:26 AM
  5. Price = zero Problems with price
    By msbaranga in forum General Questions
    Replies: 1
    Last Post: 11 Sep 2007, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg