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

  • Home
  • SEARCH
  • 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 8270019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:25:45+00:00 2026-06-08T06:25:45+00:00

I have been attempting to reorder a table in a database based on category

  • 0

I have been attempting to reorder a table in a database based on category and order id for a menu structure.

This is what I have roughly as a table structure

menuid menuname      order categoryid
--------------------------------------
1      firstitem       1      1
2      seconditem      2      1
3      thirditem       1      2
4      fourthitem      2      2

I have tried this syntax:

UPDATE yourtable SET id=IF(id=2, 3, 2) where id in(2,3)

like this:

UPDATE menu
SET order = IF(order = `3`, `2`, `3`)
WHERE order = `3`

I am getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your
 MySQL server version for the right syntax to use near 'order = IF(order = `3`, `2`, `3`)
 WHERE order = `3`' at line 2

Solution code:

UPDATE menu
SET `order` = case when `order` = 3 then 2 else 3 end
WHERE `order` = 3 AND section = 2 OR `order` = 2 AND section = 2
  • 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-06-08T06:25:47+00:00Added an answer on June 8, 2026 at 6:25 am

    try

    UPDATE menu
    SET `order` = case when `order` = 3 
                       then 2 
                       else `order` 
                  end
    

    By the way order is a reserved word in MySQL. You have to escape it with backticks

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

Sidebar

Related Questions

This question might be a bit long and specific, but I have been attempting
I have been attempting to do this for about a week. Every single time
I have been attempting this all morning (VS2K10, OL2K7, .NET 3.5) and my PSTs
I have been attempting this for a few days now. I'm creating a sprite
I have been attempting to use ASP.NET MVC remote validation for username login access
I have been attempting to learn Grails, however I am running into the following
I have been attempting to write a VBA Script that can parse out other
I have been attempting to debug my program, but it always seems to get
I have been attempting to have a object that I can use across multiple
I have been attempting to get log4net logging in my asp.net web application with

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.