1

EMP table

EMPNO   ENAME   JOB       MGR   HIREDATE    SAL    COMM DEPTNO

7369    Smith   Clerk    7902   12/17/1980  800         30
7499    Allen   Salesman 7698   2/20/1981   1600    300 30
7521    Ward    Salesman 7698   2/22/1981   1250    500 30
7566    Jones   Manager  7839   4/2/1981    2975        20
7654    Martin  Salesman 7698   9/28/1981   1250   1400 30
7698    Blake   Manager  7839   5/1/1981    2850        30
7782    Clark   Manager  7839   6/9/1981    2450        10
7788    Scott   Analyst  7566   12/9/1982   3000        20
7839    King    President      11/17/1981   5000        10
7844    Turner  Salesman 7698   9/8/1981    1500        30
7876    Adams   Clerk    7788   1/12/1983   1100        20
7900    James   Clerk    7698   12/3/1981   950         30
7902    Ford    Analyst  7566   12/3/1981   3000        20
7934    Miller  Clerk    7782   1/23/1982   1300        10

Suppose we executed the following query on the above table:

select distinct ename from emp;

Output

ENAME
Ward
Turner
Adams
Allen
Martin
Blake
Clark
Scott
Ford
King
Miller
Jones
Smith
James

Now anyone Please explain me why Ward is displayed as output in the 1st row and not in the order of the table output format??

Armunin
  • 986
  • 7
  • 18
Nikhil
  • 151
  • 1
  • 3
  • 20
  • 2
    Explained in http://stackoverflow.com/questions/899514/default-row-ordering-for-select-query-in-oracle – tvm Nov 22 '13 at 10:07

2 Answers2

2

Because you have to specify an order

select distinct ename 
from emp
order by ename 

If you don't then the DB will grab the records in the name of performance and output it unordered.

juergen d
  • 201,996
  • 37
  • 293
  • 362
1

Without ordering how you can expect ordered result.Use order by clause.