Note that there are some explanatory texts on larger screens.

plurals
  1. POA problem with getting the correct data
    primarykey
    data
    text
    <p>I have created a query that looks like this but I havent found a way to group the departments together. Thats the part I need help with. I want to get Department number in one colum, Employee is another and then the person that would be their colleague in another. Any help would be great.</p> <p>This is what I want it to look like</p> <pre><code> DEPARTMENT EMPLOYEE COLLEAGUE 10 CLARK KING 10 CLARK MILLER 10 KING CLARK 10 KING MILLER 10 MILLER CLARK 10 MILLER KING 20 ADAMS FORD 20 ADAMS JONES 20 ADAMS SCOTT 20 ADAMS SMITH </code></pre> <p>And here is what I got so far but is not correct.Kings colleague is not King its Clark and Miller. Clarks colleague is not Clark its king and Miller.</p> <pre><code> SQL&gt; select ename AS Employee, deptno AS Department, ename AS Colleague from emp order by deptno asc; EMPLOYEE DEPARTMENT COLLEAGUE ---------- ---------- ---------- KING 10 KING CLARK 10 CLARK MILLER 10 MILLER ADAMS 20 ADAMS SCOTT 20 SCOTT SMITH 20 SMITH FORD 20 FORD JONES 20 JONES WARD 30 WARD JAMES 30 JAMES ALLEN 30 ALLEN EMPLOYEE DEPARTMENT COLLEAGUE ---------- ---------- ---------- MARTIN 30 MARTIN BLAKE 30 BLAKE TURNER 30 TURNER 14 rows selected. </code></pre> <p>Heres the dept table</p> <pre><code> SQL&gt; select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON </code></pre> <p>Heres the emp table</p> <pre><code> SQL&gt; select ename, deptno, job from emp; ENAME DEPTNO JOB ---------- ---------- --------- KING 10 PRESIDENT BLAKE 30 MANAGER CLARK 10 MANAGER JONES 20 MANAGER MARTIN 30 SALESMAN ALLEN 30 SALESMAN TURNER 30 SALESMAN JAMES 30 CLERK WARD 30 SALESMAN FORD 20 ANALYST SMITH 20 CLERK ENAME DEPTNO JOB ---------- ---------- --------- SCOTT 20 ANALYST ADAMS 20 CLERK MILLER 10 CLERK 14 rows selected. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload