It seems a simple question but unfortunately I can't find examples.
Suppose that I want use the UPDATE sentence into php for updating the last 10 records of my table "users" of Database "users". what its the code for that? I mean INSERT sentence have a
answer for that using LIMIT etc, but UPDATE dont have it.
Thanks in advance for your help.
pd: For example, I want to update "Firstname" field with "michael" word in the last 10 records.
Try this
UPDATE table SET notes="hi"
ORDER BY id DESC
LIMIT 10
As per Mysql docs, if there is a unique column, order by it DESC, and use LIMIT 10 to select last 10 records.
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With