Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:41:47+00:00 2026-05-16T23:41:47+00:00

how do I do multiple updates within same query. Lets say I have this

  • 0

how do I do multiple updates within same query.

Lets say I have this query

UPDATE table1
SET
Order = 1
WHERE
ID = 1234  

But I want to change some more orders where IDs are 2345 and 2837 and 8399
how would I do that within same mysql query. Please notice that Order may be different than 1 for those. as order field is unique.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:41:47+00:00Added an answer on May 16, 2026 at 11:41 pm
    UPDATE table1
    SET Order = 1
    WHERE id IN (1234, 2345, 2837, 8399)
    

    If you need different values of Order for each id, then you probably want to put a loop in whatever program is talking to the database.

    Edited to add

    I was thinking of looping in a program, but I see you want to execute the SQL interactively.

    If you’re trying to bundle a sequence of unpredictable numbers like this:

    UPDATE table1  Order = 1 WHERE id = 1234
    UPDATE table1  Order = 2 WHERE id = 2345
    UPDATE table1  Order = 3 WHERE id = 2837
    UPDATE table1  Order = 5 WHERE id = 8399
    UPDATE table1  Order = 8 WHERE id = 8675
    

    …then I’m not sure how you want that to be shorter. You can write a stored procedure that gets called like this:

    do_table1_update "1,2,3,5,8,13", "1234,2345,2837,8399,8675,309"
    

    Is that what you have in mind?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have multiple commands like 5000 which updates some column and row
How can I update multiple values in MySQL? This didn't work: UPDATE test SET
Should multiple developers work within the same branch, and update - modify - commit
Have seen multiple posts on this but I can't see any which answer my
On my page I have multiple forms all the same as this... <form class='bill-upd'>
I want to save a set of queries (multiple SQL updates) as a single
I have a scenario where I have to update multiple rows in a table
See update below. This is driving me mad. I have followed all the instructions
I was wondering if the below way of handling multiple sql's within the same
http://www.programmersheaven.com/2/FAQ-ADONET Disconnected architecture is not well suited for desktop clients with multiple updates but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.