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 6907547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:26:55+00:00 2026-05-27T08:26:55+00:00

My Table contains Three columns and the value looks like the following Emp_ID |

  • 0

My Table contains Three columns and the value looks like the following

Emp_ID |  Emp_Name   |  Emp_Manager_ID
========================================
1      |  Admin      |   Null         
2      |  John       |   1            
3      |  Sam        |   2             
4      |  Mike       |   2            
5      |  Jeff       |   4            
6      |  Ben        |   3            
7      |  Vicky      |   5

The parameter id @Emp_ID = 2
The expected result to find all the subordinates under the given Emp_Id
so the result should be all EmpIDs 3,4,5,6,7
because 2 is the manager of 3,4 and 3 is the manager of 6, 4 is the manager of 5 and 5 is the manager of 7

  • 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-27T08:26:56+00:00Added an answer on May 27, 2026 at 8:26 am

    Using a Recursing CTE. This currently returns all three columns. Remove Emp_Name and Emp_Manager_ID from the SELECT if you do not require that information.

    WITH Subordinates AS
    (
       SELECT e.Emp_ID, e.Emp_Name, e.Emp_Manager_ID
       FROM Employee AS e
       WHERE e.Emp_Manager_ID = 2
       
       UNION ALL
    
       SELECT e.Emp_ID, e.Emp_Name, e.Emp_Manager_ID
       FROM Employee AS e
       INNER JOIN Subordinates AS sub ON e.Emp_Manager_ID = sub.Emp_ID
    )
    SELECT s.Emp_ID, s.Emp_Name, s.Emp_Manager_ID
    FROM Subordinates AS s
    

    Example of query running using Employee_ID = 1:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which contains an Assignment table. The table looks like this:
I have a table TableX . It contains three columns: A INT , B
I have a table that contains three columns. column1 column2 column3 mytestdata test myotherdata
I have a table with three columns, and two cells contain select boxes with
As shown below the Table Recording contains three foreign keys, only one of which
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
My table have following columns, (copy to create test table) CREATE TABLE dbo.[PDNApprovalDetail]( [PDNApprovalMasterID]
I have an HTML Table that looks like this: The user can update any
Kinda stuck on this one. I have a table with name/value columns: NameValue table
I am using MySQL 5.1.56, MyISAM. My table looks like this: CREATE TABLE IF

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.