sql - UNION Query Error -
i have following 2 tables(dept , emp):
dept deptno,dname,loc emp empno, ename,job,mgr,hiredate,sal,comm,deptno
i'm executing following query: "use union display department numbers , names , employee numbers , names. choose appropriate column headings , sort name in ascending order."
here query:
select deptno, dname dept order dname asc union select empno,ename emp order ename asc;
i'm wondering why i'm getting following error:
union * error @ line 4: ora-00933: sql command not ended.
could please tell me what's wrong here?
thanks
try this
select deptno id, dname name dept union select empno id,ename name emp order name asc
edit
to display 4 columns check below query using join
select e.empno ,e.ename ,d.deptno , d.dname dept d inner join emp e on e.deptno = d.deptno order e.ename asc
Comments
Post a Comment