Results 1 to 5 of 5
  1. #1
    Join Date
    May 2012
    Posts
    155

    Unanswered: the sort in database vs. sorting from select-command

    Hallo everyone,

    I am using a database client tool. It seems like, the sorting of the records I can see in the tool is different to the sorting if I run:

    Code:
    select * from mytable
    fetch first 10 rows only;
    So, the first 10 rows I can see without running above command is different to the result of the command. Anyone an idea why it is like this?

    Thank you.

    Regards,
    Ratna

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    There is no sorting in your query. Data in the database do not have any inherent order. To sort query results, user the ORDER BY clause. In all other cases the order of results is undefined.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    May 2012
    Posts
    155
    hallo n_i,

    ooh.. the data has no particular order in the database. Even if I sort the records in the database by a clicking a particular column such as "customerNumber", the result from sql-command with order by option will not give me the sorted results, as the sorting I have done in the database is just optical?

    On the other side, this command will give me the information in which sort the first 10 rows are really stored in the database. Is that correct?

    Code:
    SELECT * FROM myTable FETCH FIRST 10 ROWS ONLY
    Thank you.

    Regards,
    Ratna

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by ratnalein View Post
    I sort the records in the database by a clicking a particular column
    This does not sort records in the database, obviously, because there is no clicking on the database. What it sorts is a bunch of variables in whatever application it is that you're clicking in.

    Quote Originally Posted by ratnalein View Post
    this command will give me the information in which sort the first 10 rows are really stored in the database. Is that correct?

    Code:
    SELECT * FROM myTable FETCH FIRST 10 ROWS ONLY
    No necessarily. They will come out in whatever order the optimizer chooses, if any.
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    May 2012
    Posts
    155
    thank you very much n_i.

    Regards,
    Ratna

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •