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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:59:09+00:00 2026-05-26T22:59:09+00:00

In MySQL while using IN operator can we ask MySQL to return result-set(record-set) in

  • 0

In MySQL while using IN operator can we ask MySQL to return result-set(record-set) in same order as the IN set was?

explanation:
Suppose we have a table
items (item_id, item_name);

and the query:

select * from items where item_id in (1,3,5,7,2,4,6,8);

can we have the result-set(record-set) where the records are in same order as IN operator set.
i.e 1,3,5,7,2,4,6,8 of record_ids

This isn’t the case; MySQL seems to optimise out the search and gives the default order(same as order of those records stored on File-system).

  • 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-26T22:59:09+00:00Added an answer on May 26, 2026 at 10:59 pm

    You could use MySQL’s field function in your ORDER BY clause:

    select *
    from items
    where item_id in (1,3,5,7,2,4,6,8)
    order by field(item_id, 1,3,5,7,2,4,6,8)
    

    The field function:

    FIELD(str,str1,str2,str3,...)

    Returns the index (position) of str in the str1, str2, str3, … list. Returns 0 if str is not found.

    If all arguments to FIELD() are strings, all arguments are compared as strings. If all arguments are numbers, they are compared as numbers. Otherwise, the arguments are compared as double.

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

Sidebar

Related Questions

$result = mysql_query(SELECT * FROM project ORDER BY projectid); while($row = mysql_fetch_array($result)) { return(array($row['projectid'],
while using database under MySQL how can i determine my current MySQL version,database name
I was wondering if it's possible to have 2 'while' statements using the same
Been using PHP/MySQL for a little while now, and I'm wondering if there are
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have a problem with relations while using sqlite3 on rails. First i build
I'm using while($stmt->fetch()) to loop though the results I get from a MySQL Query,
If I am fetching data from a MySQL database and using a while loop
I have an alternating rows using PHP: while($i < $num) { $idphysicians = mysql_result($qPhysician,$i,idphysicians);
I have successfully created Web Services from MySQL Database using Netbeans tutorial . However,

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.