Jay
Jay

Reputation: 540

SQL Subquery assistance. Simple Code is giving error message

I am trying to create a query that will display the name, dep no. , and all the workers that work in the same dep as a specific person. I have written some code for it but its giving an error.

SELECT d.deptno ,d.ename , e.ename
FROM   emp e, emp d
WHERE  deptno = ( SELECT  DISTINCT deptno
                  from emp
                  WHERE  d.deptno = e.deptno );

Cheers

-Jay

Upvotes: 2

Views: 438

Answers (1)

user359040
user359040

Reputation:

Try:

SELECT d.deptno AS DEPARTMENT,d.ename AS EMPLOYEE , e.ename AS COLLEAGUE
FROM   emp e, emp d
WHERE  d.deptno = e.deptno AND d.ename <> e.ename;

Upvotes: 2

Related Questions