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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:49:43+00:00 2026-06-05T17:49:43+00:00

If items are inserted in a table, and then I write a query, such

  • 0

If items are inserted in a table, and then I write a query, such as select * from table, why are the results not in the order that I expect?

  • 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-05T17:49:45+00:00Added an answer on June 5, 2026 at 5:49 pm

    The order of a query can be forced by using an ‘Order by’ Clause in the statement. A SQL Database does not actually understand what order you put things in, or store the data in a given order. This means that you need to tell SQL what order you want the items in. For instance:

    Select * from Table
      order by column1 desc
    

    Think about it like handing some stuff to your friend to hold – she will have all of it for you later, but she stores it someplace in the mean time. She may move it around while you are not looking to make room for something else, or may hand it back in the same order you gave it to her, but you didn’t tell her to keep it in order, so she doesn’t.

    Databases need to be able to move things around in the background, so the way they are built does not intrinsically know about any order – you need to know the order when you give it to the database, so that you can put it back in the order you want later. The order clause allows SQL to impose an order on the data, but it doesn’t remember or have one on its own.

    Important point: Even when SQL returned the items in the correct order without an order by statement the last 1 million times, it does not guarantee that it will do so. Even if a clustered index exists on the table, the results are not guaranteed to be returned in the order you expect. Especially when SQL versions change, not explicitly using an order by clause can break programs that assume the query will be in the order they want!

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

Sidebar

Related Questions

i am querying the DB as follows: $result=mysql_query(SELECT name,items FROM mytable WHERE price='$price'); now,i
I need to do a SELECT in 8 tables, but the results in not
I have a table Items which stores fetched book data from Amazon. This Amazon
I have a table orderDetails that contains the products of an order productId color
I have this query, which was working fine. SELECT SUM(amount) FROM company.invoice_line WHERE item_id
Each day hundreds of thousands of items are inserted, updated and deleted on our
If items are organized randomly, how does the table know where to start looking?
I have one (items [id, name, color, size, etc] ) table with more than
I have items, that have price, color, manufacturer, model and so on. I want
I wrote a method that gathers data from an Oracle server, formats and encrypts

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.