Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:00:44+00:00 2026-05-25T16:00:44+00:00

I have created a query that looks like this but I havent found a

  • 0

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.

This is what I want it to look like

  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

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.

    SQL> 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.

Heres the dept table

 SQL> select * from dept;

DEPTNO DNAME          LOC
---------- -------------- -------------
    10 ACCOUNTING     NEW YORK
    20 RESEARCH       DALLAS
    30 SALES          CHICAGO
    40 OPERATIONS     BOSTON

Heres the emp table

 SQL> 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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:00:45+00:00Added an answer on May 25, 2026 at 4:00 pm

    It sounds like you want something like

    SQL> ed
    Wrote file afiedt.buf
    
      1  select deptno department,
      2         e1.ename employee,
      3         e2.ename colleague
      4    from emp e1 join emp e2 using (deptno)
      5   where e1.empno != e2.empno
      6*  order by deptno
    SQL> /
    
    DEPARTMENT EMPLOYEE   COLLEAGUE
    ---------- ---------- ----------
            10 MILLER     CLARK
            10 KING       CLARK
            10 MILLER     KING
            10 CLARK      MILLER
            10 KING       MILLER
            10 CLARK      KING
     <<additional results removed>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NHibernate query that looks like this: var query = Session.CreateQuery(@ select
I have a query that creates a result set like this: Rank Name 1
I have a set of data that looks like this when using print_r($var) :
I have written a query with codeigniters database library, it looks like this, public
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,
I have a SELECT statement that looks like this: SELECT * FROM photos, p_votes
I have an object that looks something like this: public class Student { public
I have some data that looks like this: [ { _id : ObjectId(4e2f2af16f1e7e4c2000000a), advertisers
I have created a T-SQL query in SQL Server 2008 R2 that is a
I have a query that is more complicated, but basically creates an HTML page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.