Question:

What is the default sorting order in SQL?

by  |  earlier

0 LIKES UnLike

When we select some data from a table in SQL, without specifying the sorting order then what default sorting order is used by the SQL.

 Tags:

   Report

4 ANSWERS


  1. The returned order is the order of the records in your table, and most probably the order in witch the records where added.


  2. if you don't specify the order you want, the data will be presented in the order the records were added to the table  

  3. Without a specific ORDER BY, the rows will be returned in an unpredictable way. Often, this will be the order the rows physically exist in the tablespace, but not necessarily so. If there are one or more indexes defined for the database, some database engines (for example, DB2) may determine at bind time that using some of them will improve retrieval efficiency. In that case, the order will depend on the index(es) used. Also, other elements (GROUP BY, subselects, etc.) may cause some internal sorting of rows to determine the result set. In any case, it's not 100% dependable.

  4. If there is no "ODER BY" clause, then you can never know in what order the result set is returned.

    If you have an "ORDER BY" clause, every flavor of SQL that I know defaults to ascending.

    If you must have the result set in a specific sort order, then you must have an "ORDER BY" clause. Period.

    Ex:

    Select

      Purch_date,

      Cust_Num

    From

      Cust_Orders

    Where

      Cust_Num = 123

    Order By

    Purch_Date ascending;

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.