Jump to content

Archived

This topic is now archived and is closed to further replies.

Jessica

How to order in UPDATE when using limit by?

Recommended Posts

I am performing this query:
$update_item = "UPDATE stall_transactions SET cleared = 1 WHERE stall_id = $stall_id LIMIT 50";

I want it to update the 50 most recent by either sold (datetime) or transaction_id (primary key).

How can I ensure it does the 50 most recent?

Thanks!
ps: the new forum design is awesome!

Share this post


Link to post
Share on other sites
Baffled me for a minute, but I was sure it was possible, so I had a look over at mysql.com.

The following is the syntax for UPDATE. As long as you get the order correct, I'm sure you will have no problems.

[code]
UPDATE [LOW_PRIORITY] [IGNORE] tbl_name
    SET col_name1=expr1 [, col_name2=expr2 ...]
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]
[/code]

Share this post


Link to post
Share on other sites
Yup... just add the necessary ORDER BY clause and you're set.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.