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 7062157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:33:37+00:00 2026-05-28T04:33:37+00:00

I’m not even sure if this is quite possible to do with MySQL, but

  • 0

I’m not even sure if this is quite possible to do with MySQL, but I hope it is.

OK so i have this SQL command

SELECT * FROM table WHERE $WhereCondition ORDER BY ListStyle

As an example of the data in the ListStyle I might have

2000 3000 3700 3800

What I’m hoping to do is use some kind of if statement in the SQL that will allow me to check other fields in a result row so that I can change the value of the ListStyle before I use that in the page to order it appropriately.

So for instance I have fields a, b and c. Now if a and b are NOT empty and c = 100 and the ListStyle = 3700, I want to change the value of ListStyle to 3699 so that when I print out a result loop, rows that match the condition ( a != '', b != '', c = 100 and ListStyle = 3700) will then be shown above the rows that have the ListStyle of 3700

I can’t simply edit the data in the database, even though that would be an easy solution. The data has to stay as it is.

I originally tried doing this in php. While its easy enough to change the value of the ListStyle using if statements, I don’t know of an easy way to then actually order my results without sticking everything into an array and then sorting through it. I really don’t want to do that as it would mean re-writing a lot of code, which is why I’m hoping this is all possible to do in MySQL.

Can anyone help with this?

  • 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-28T04:33:38+00:00Added an answer on May 28, 2026 at 4:33 am

    try something like:

    SELECT * FROM table_name WHERE $WhereCondition ORDER BY CASE 
            WHEN ( a = 0, b = 0, c = 100 and ListStyle = 3700)  THEN 1
            WHEN ( a = 10, b = 20, c = 200 and ListStyle = 3400) THEN 2
            ELSE 10
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.