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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:00:22+00:00 2026-05-24T02:00:22+00:00

I have been searching for an existing question for this one, but i am

  • 0

I have been searching for an existing question for this one, but i am not sure what to search for. I am looking for a way to order my results based on a list of id’s and a second variable.

Imagine the following record set

user_id  user_name
------------------
   1       Peter
   2       John
   3       Luke
   4       Tim
   5       George
   6       Michael
   ~       etcetera

Now, I have a list of user ids (lets say 1,4,5) that I want the result of my query to start with.

So i thought:

 // Edit: replaced 'AND' with ','
 SELECT * FROM `user` ORDER BY `user_id` IN (1,4,5), `name`

Would return something like:

user_id  user_name
------------------
   1       Peter   <-- Notice the 1,4,5 at the top
   4       Tim
   5       George
   2       John    <-- After that its just alphabetical
   3       Luke
   6       Michael
   ~       etcetera

But it doesn’t.. It looks like it just ignores the sorting directives. Does anyone know what I am doing wrong? Is it even possible to do something like 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-24T02:00:23+00:00Added an answer on May 24, 2026 at 2:00 am

    Try this:

     SELECT * 
            FROM    `user` 
        ORDER BY 
            CASE 
                WHEN `user_id` IN (1,4,5) THEN 1
                ELSE `user_id`
            END,
            `name` 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sure this is a silly question, but I have been searching for
I have been searching a lot to find a way to do this. But
I have been searching on a question like this but I cant find it.
Have been searching how to convert a dictionary to a string. But the results
I think this question is probably fairly simple, but I've been searching around and
I have been searching all over the Internet, but did not find that exact
I have been searching and this problem seems simple but cannot find answer. I
I have asked this question in Radiant CMS google group, but no one answered
Have been searching over the Graph API docs, looking for the answer to this.
I have been searching everywhere but can't seem to find a solution to this

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.