Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Why can't I ORDER BY in this UNION ?

York35Mar 16 2017 — edited Mar 16 2017

DB version: 11.2

Why can't I ORDER BY in this UNION ?

SQL> set lines 200 pages 200

SQL> select * from emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO

---------- ---------- --------- ---------- --------- ---------- ---------- ----------

      7369 SMITH      CLERK           7902 17-DEC-80        800                    20

      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30

      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30

      7566 JONES      MANAGER         7839 02-APR-81       2975                    20

      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30

      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30

      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20

      7839 KING       PRESIDENT            17-NOV-81       5000                    10

      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30

      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20

      7900 JAMES      CLERK           7698 03-DEC-81        950                    30

      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20

12 rows selected.

--- Creating a clone of emp for demo purpose

SQL> create table emp_clone as select * From emp;

Table created.

SQL> select * from emp

  union

  select * from emp_clone order by hiredate asc;

select * from emp_clone order by hiredate asc

                                 *

ERROR at line 3:

ORA-00904: "HIREDATE": invalid identifier

-- Attempt2 (Same error )

select * from emp

union

select * from emp_clone ec order by ec.hiredate asc;

ERROR at line 3:

ORA-00904: "EC"."HIREDATE": invalid identifier

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 13 2017
Added on Mar 16 2017
14 comments
1,344 views