Free YouTube views likes and subscribers? Easily!
Get Free YouTube Subscribers, Views and Likes

SQL Interview Question 2024 | Recursive CTE to retrieve the hierarchical structure of employees

Follow
Data Science Corner

In this video, I have discussed how to solve the SQL Interview Questions: Write an SQL query using a recursive CTE to retrieve the hierarchical structure of employees.

Creating the Employees Table

CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY, Unique identifier for each employee
ManagerID INT NULL, This refers to the EmployeeID of the manager (NULL if toplevel employee)
EmployeeName VARCHAR(100) NOT NULL Name of the employee
);

Inserting Sample Data

INSERT INTO Employees (EmployeeID, ManagerID, EmployeeName)
VALUES
(1, NULL, 'Alice'),
(2, 1, 'Bob'),
(3, 1, 'Charlie'),
(4, 2, 'David'),
(5, 2, 'Eve'),
(6, 3, 'Frank'),
(7, 4, 'Grace');

SQL Interview QnAs:    • SQL Interview Questions and Answers  

PySpark Basic to Advance:    • PySpark Tutorial  

Python Basic to Advance Handson:    • Python for Data Science | Hands on Co...  

Resume Building and Interview Preps:    • Resume Building and Interview Preps I  

***Join our Telegram Group for regular updates on Jobs and Data Science materials:
https://t.me/datasciencecorner'>https://t.me/datasciencecorner
https://t.me/datasciencecorner'>https://t.me/datasciencecorner

Instagram:
https://bit.ly/3LKnSmw'>https://bit.ly/3LKnSmw
https://bit.ly/3LKnSmw'>https://bit.ly/3LKnSmw

LinkedIn:
  / data.  .
  / data.  .




#sql #sqlfordataengineer #jobinterview #technicalinterview #postgresql #deloitte #deloittejobs #capgeminihiring #cognizant #infosys #tcs #genpactjobs #kpmg #mysql #interview #dataengineering #dataanalytics #dataanalysis #capgemini #capgeminijobs #sqlfordataengineer #coding #programming #learningvideos #technical

posted by Annermhamg9