My table has data like so
products_parent_id | products_quantity 2 5 2 7 2 9 2 4
My SQL statement looks like so (so far):
UPDATE ' . TABLE_PRODUCTS . ' SET products_quantity = products_quantity +' . $order['products_quantity'] . ', products_ordered = products_ordered - ' . $order['products_quantity'] . ' WHERE products_parent_id = ' . (int)$order['products_id']
Now what I want to do, is update only say the 3rd occurrence of products_parent_id (in this case, 3rd from the top is 9)
To SELECT the 3rd occurrence, I used this at the end of my statements LIMIT($grade, 1)
Is there a way to UPDATE using MySQL but only the 3rd/4th/etc occurrence? Will it be reliable?
Thank you
Short Answer: No
Long Answer:
Sort Of. Because the order the rows are returned is not defined by SQL.
Technically two different requests to the DB could return the rows in a different order. So even if you update the third row, which is the third will depend on the implementation.
The only way to mitigate this is to apply a specific ordering to the rows. (Order by)
I don’t think it is part of the language specification but most SQL implementations allow you to get a particular row from a query. I am not sure what the MYSQL specific details are but a quick google got this page:
http://forums.mysql.com/read.php?10,36490,36511