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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:06:21+00:00 2026-06-18T04:06:21+00:00

I have following table with data emp_no emp_name login HOD_code Level E43057 Ankita Barde

  • 0

I have following table with data

emp_no  emp_name        login  HOD_code  Level  
E43057  Ankita Barde     9:45  P00212    Direct 
E33995  Rakesh Sharma    8:15  P00212    Direct 
E31446  Amit Singh      10:45  P00212    Direct 
E44920  Shweta Salve     9:38  E33995    Indirect   
E39787  Anita Shenoy     9:15  E31446    Indirect   
E37731  Ramesh Shukla    9:10  E31446    Indirect   
E43455  Manish Shukla   11:01  E33995    Indirect   
E43130  Lubna Shaikh     9:39  E33995    Indirect

In the above table I have one HOD code (P00212) superior to all so employee which are mapped under P00212 are specified as direct employee in the LEVEL column and all others are indirect to P00212. But this indirect employees are mapped under Direct Employee
For eg: P00212 is HOD of Rakesh Sharma (E33995) and E33995 is HOD of 3 other employe i.e Shweta(E44920), E43455, E43130. So I want to write a query in such way that the output will look like the following

OUTPUT:

emp_no  emp_name        login  HOD_NO  Level    
E43057  Ankita Barde     9:45  P00212  Direct

E33995  Rakesh Sharma    8:15  P00212  Direct   
E43455  Manish Shukla   11:01  E33995  Indirect 
E43130  Lubna Shaikh     9:39  E33995  Indirect 
E44920  Shweta Salve     9:38  E33995  Indirect

E31446  Amit Singh      10:45  P00212  Direct   
E39787  Anita  Shenoy    9:15  E31446  Indirect 
E37731  Ramesh Shukla    9:10  E31446  Indirect 

How can I do this?

  • 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-06-18T04:06:22+00:00Added an answer on June 18, 2026 at 4:06 am

    SQLFiddle Example

    select * from t
    order by CASE WHEN HOD_CODE='P00212' THEN EMP_NO ELSE HOD_CODE END,
             CASE WHEN HOD_CODE='P00212' THEN 0 ELSE 1 END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following type of login/logout data. I'm trying to
I have a table emp with following structure and data: name dept salary -----
Suppose we have the following table data: ID parent stage submitted 1 1 1
I have the following table and data docRefID docExternalContent 1 'a' 1 'b' 1
I have the following table: CREATE TABLE [dbo].[Data] ( [Id] UNIQUEIDENTIFIER NOT NULL, [Data]
I have the following table template that is rendered through knockout: <table class=gv data-bind=visible:
I have the following table: ID | JobID | Data | ResultType --------------------------------- 1
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have some data in a table that looks roughly like the following: table

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.