Last data from Product

Hello Guys i need your help i just start to learn and i have some trouble to resolve this task

i need to check in table last id product because they repeat some times

i explain better in bms_procurement_purchase_order_product have row product_id and inside this row i have some id repeat and so i need select last data in this row, i already done the script but now i dont understand how to write that this script need take last data in product_id and also have row id_bms_procurement_purchase_order_product

So i think need group but i dont know how

$sql = “UPDATE " . _DB_PREFIX_ . "product_shop as o inner join " . _DB_PREFIX_ . "bms_procurement_purchase_order_product as co on o.id_product=co.product_id SET o.wholesale_price = co.price”;
if (!Db::getInstance()->Execute($sql)){

//End Step 1


^^^ Don’t do that. By storing the same data values in multiple places, your data can easily get out of sync or you spend a lot of time doing extra things to keep it in sync.

Instead, query to get the correct source value when needed. To get the latest/highest id row per group of row(s), use a query like the following -

SELECT your_columns
 FROM your_table
add any JOINed tables and conditions here...
    SELECT MAX(id)
      FROM your_table
      WHERE any_conditions_to_match_specific_rows
      GROUP BY the_common_element_in_the_data


I think you are right.

But i need take last data from table hot to do

Sponsor our Newsletter | Privacy Policy | Terms of Service