Jump to content

How to order in UPDATE when using limit by?


Jessica

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!
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.